示例#1
0
func main() {
	fmt.Println("Testing Frala Parsing")
	parsedResponse := frala.Parse("page.html") // Parse page.html

	if parsedResponse.Error == nil { // If there was no parse error, because we're awesome
		fmt.Println(parsedResponse.Content) // Output parsedContent
	} else { // If we failed to parse
		fmt.Println("You fool, you doomed us all! Okay, not really, but here is the error message: ", parsedResponse.Error)
	}

	fmt.Println("Testing GetDirection for lang: en")
	fmt.Println(frala.GetDirection("en"))

	fmt.Println("Testing GetDirection for lang: ar")
	fmt.Println(frala.GetDirection("ar"))

	fmt.Println("\nTesting Po functionality")

	fmt.Println("Running ConvertToPo for lang: en")
	fmt.Println(frala.ConvertToPo("en"))

	fmt.Println("\nRunning ConvertToPo for lang: fi")
	finnishPoContent := frala.ConvertToPo("fi")
	fmt.Println(finnishPoContent)

	if len(finnishPoContent) != 0 {
		ioutil.WriteFile("finnish.po", []byte(finnishPoContent), 0777) // Write the contents to finnish.po
		fmt.Println("\nRunning ConvertFromPo")
		convertError := frala.ConvertFromPo("finnish.po")

		if convertError == nil { // If there was no conversion error
			fmt.Println("No conversion error. Terms below:\n")
			fmt.Println(frala.Config.Terms)
		} else { // Error converting from PO
			fmt.Println("There was an issue converting from Po: ", convertError)
		}

		os.Remove("finnish.po")
	} else { // No convent in finnishPoContent
		fmt.Println("No content from ConvertToPo for Finnish.")
	}
}
示例#2
0
// PoConversion will handle conversion to/from Po
func PoConversion(convertTerms bool, poFile string) {
	if strings.HasSuffix(poFile, ".po") { // If the file is a .po file
		if convertTerms { // If we are converting Terms to Po
			os.MkdirAll(TargetDirectory, 0755)                                    // Ensure the target directory exists
			poFileContent := frala.ConvertToPo(frala.Config.DefaultLanguage)      // Convert the Terms of the language defined (or default language)
			ioutil.WriteFile(TargetDirectory+poFile, []byte(poFileContent), 0755) // Save the Po contents to the poFile in the target directory
		} else { // If we are converting Po to Terms
			conversionError := frala.ConvertFromPo(poFile) // Convert the poFile to Frala Terms

			if conversionError == nil { // If there was no conversion error
				frala.Config.DefaultLanguage = OriginalLanguage // Ensure the default language is maintained after importing from Po
				frala.SaveConfig()                              // Save the config
			} else { // If there was a conversion error
				fmt.Println(conversionError)
			}
		}
	} else {
		fmt.Println(poFile + " does not appear to be a Po file. Please ensure the extension is .po")
	}
}