Пример #1
0
func main() {
	nflag.Parse() // Parse nflag

	OriginalLanguage = frala.Config.DefaultLanguage                     // Set OriginalLanguage before doing any parsing or conversion
	frala.Config.DefaultLanguage, _ = nflag.GetAsString("lang")         // Change DefaultLanguage to whatever may be set as lang. This may not change if no value is passed to lang
	frala.Config.Direction = frala.GetDirection(frala.Config.Direction) // Ensure we have an accurate Direction

	parseFiles, parseFilesErr := nflag.GetAsString("parse")
	poFile, poFileErr := nflag.GetAsString("po")

	TargetDirectory, _ = nflag.GetAsString("target-dir")
	TargetDirectory += "/" // Ensure / is appending to end of path

	if (parseFilesErr == nil) && (parseFiles != "") { // If we are parsing files
		ParseFiles(parseFiles) // Call ParseFiles
	} else if (poFileErr == nil) && (poFile != "") { // If we are doing Po conversion
		convertTermsVal, convertTermsGetErr := nflag.GetAsBool("convert-terms") // Get the boolean value of convert-terms

		if convertTermsGetErr != nil { // If there was an error getting convertTermsVal
			convertTermsVal = false // Don't convert from Terms to Po
		}

		PoConversion(convertTermsVal, poFile) // Do Po conversion
	} else { // If we are neither parsing nor doing Po conversion
		nflag.PrintFlags() // Print the nflag flags
	}
}
Пример #2
0
// FralaParser gets the directory contents of tests/design (if it exists) and parse the files with Frala.
func FralaParser(rootDirectory string, files []string) {
	if len(rootDirectory) != 0 && rootDirectory != "/" { // If the rootDirectory has content but NOT /
		rootDirectory += "/" // Append / to end of rootDirectory

		var fileNamesWithoutDir []string                             // Define filesWithoutDir as an empty []string that'll contain names of files without the directory string
		languagesToRecurse := []string{frala.Config.DefaultLanguage} // Set languagesToRecurse to a string slicen with Default Language by default

		if len(frala.Config.Languages) != 0 { // If pre-defined languages have been set
			languagesToRecurse = frala.Config.Languages // Set languagesToRecurse to the languages defined
		}

		for _, fileName := range files { // For each file in files
			fileNamesWithoutDir = append(fileNamesWithoutDir, filepath.Base(fileName)) // Append only the file name
		}

		for _, language := range languagesToRecurse { // For each language
			frala.Config.DefaultLanguage = language                                   // Change DefaultLanguage in Frala to language
			frala.Config.Direction = frala.GetDirection(frala.Config.DefaultLanguage) // Ensure we have an accurate Direction against the updated DefaultLanguage

			listOfParseResponses := frala.MultiParse(files) // Parse all the HTML files in tests/design, return the ParseResponses

			for fileName, parseResponse := range listOfParseResponses { // For each file and parseResponse in listOfParseResponses
				if len(parseResponse.Content) != 0 && parseResponse.Error == nil { // If there is content returned from the parsing and there is no error
					codeutilsShared.WriteOrUpdateFile(rootDirectory+language+"/"+filepath.Base(fileName), []byte(parseResponse.Content), codeutilsShared.UniversalFileMode) // Update the file in lang specific design dir
				}
			}

			CompressHTML(rootDirectory+language, fileNamesWithoutDir) // Compress all the HTML files provided in this language directory
		}

		for _, fileName := range fileNamesWithoutDir { // For each file in fileNamesWithoutDir
			os.Remove(rootDirectory + fileName) // Remove the file in tests/design now that we have compressed forms in each individual language folder in tests/design
		}
	}
}
Пример #3
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.")
	}
}