Refactor to parseAllWords()

This commit is contained in:
Gucheng Wang 2023-03-18 14:16:15 +08:00
parent 28d24cc913
commit d383de256b
2 changed files with 26 additions and 26 deletions

View File

@ -99,7 +99,7 @@ func getAllFilePathsInFolder(folder string, fileSuffix string) []string {
return res return res
} }
func parseEnData(category string) *I18nData { func parseAllWords(category string) *I18nData {
var paths []string var paths []string
if category == "backend" { if category == "backend" {
paths = getAllFilePathsInFolder("../", ".go") paths = getAllFilePathsInFolder("../", ".go")
@ -137,10 +137,10 @@ func parseEnData(category string) *I18nData {
return &data return &data
} }
func applyToOtherLanguage(category string, language string, i18nData *I18nData) { func applyToOtherLanguage(category string, language string, newData *I18nData) {
newData := readI18nFile(category, language) oldData := readI18nFile(category, language)
println(newData) println(oldData)
applyData(i18nData, newData) applyData(newData, oldData)
writeI18nFile(category, language, i18nData) writeI18nFile(category, language, newData)
} }

View File

@ -20,29 +20,29 @@ package i18n
import "testing" import "testing"
func TestGenerateI18nFrontend(t *testing.T) { func TestGenerateI18nFrontend(t *testing.T) {
enData := parseEnData("frontend") data := parseAllWords("frontend")
applyToOtherLanguage("frontend", "en", enData) applyToOtherLanguage("frontend", "en", data)
applyToOtherLanguage("frontend", "zh", enData) applyToOtherLanguage("frontend", "zh", data)
applyToOtherLanguage("frontend", "es", enData) applyToOtherLanguage("frontend", "es", data)
applyToOtherLanguage("frontend", "fr", enData) applyToOtherLanguage("frontend", "fr", data)
applyToOtherLanguage("frontend", "de", enData) applyToOtherLanguage("frontend", "de", data)
applyToOtherLanguage("frontend", "ja", enData) applyToOtherLanguage("frontend", "ja", data)
applyToOtherLanguage("frontend", "ko", enData) applyToOtherLanguage("frontend", "ko", data)
applyToOtherLanguage("frontend", "ru", enData) applyToOtherLanguage("frontend", "ru", data)
applyToOtherLanguage("frontend", "vi", enData) applyToOtherLanguage("frontend", "vi", data)
} }
func TestGenerateI18nBackend(t *testing.T) { func TestGenerateI18nBackend(t *testing.T) {
enData := parseEnData("backend") data := parseAllWords("backend")
applyToOtherLanguage("backend", "en", enData) applyToOtherLanguage("backend", "en", data)
applyToOtherLanguage("backend", "zh", enData) applyToOtherLanguage("backend", "zh", data)
applyToOtherLanguage("backend", "es", enData) applyToOtherLanguage("backend", "es", data)
applyToOtherLanguage("backend", "fr", enData) applyToOtherLanguage("backend", "fr", data)
applyToOtherLanguage("backend", "de", enData) applyToOtherLanguage("backend", "de", data)
applyToOtherLanguage("backend", "ja", enData) applyToOtherLanguage("backend", "ja", data)
applyToOtherLanguage("backend", "ko", enData) applyToOtherLanguage("backend", "ko", data)
applyToOtherLanguage("backend", "ru", enData) applyToOtherLanguage("backend", "ru", data)
applyToOtherLanguage("backend", "vi", enData) applyToOtherLanguage("backend", "vi", data)
} }