diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-03 11:12:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 11:12:47 +0800 |
commit | c2ff2a472435c9735b8fef78c3797e54b99c73ad (patch) | |
tree | e8314966f316f5119b041caa2d8b91fb0feb864c /build | |
parent | f020fc27e523d9ab68ccc066c0d764baca4bead9 (diff) | |
download | gitea-c2ff2a472435c9735b8fef78c3797e54b99c73ad.tar.gz gitea-c2ff2a472435c9735b8fef78c3797e54b99c73ad.zip |
Try to catch more broken translations (#23867)
Result: #23866
Gitea should drop the ``` ` ``` as string quoter, it is not recognized
by Crowdin and it causes problem for translators.
Diffstat (limited to 'build')
-rw-r--r-- | build/backport-locales.go | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/build/backport-locales.go b/build/backport-locales.go index a717b37367..054b623d69 100644 --- a/build/backport-locales.go +++ b/build/backport-locales.go @@ -62,6 +62,7 @@ func main() { // use old en-US as the base, and copy the new translations to the old locales enUsOld := inisOld["options/locale/locale_en-US.ini"] + brokenWarned := map[string]bool{} for path, iniOld := range inisOld { if iniOld == enUsOld { continue @@ -77,11 +78,14 @@ func main() { if secNew.HasKey(keyEnUs.Name()) { oldStr := secOld.Key(keyEnUs.Name()).String() newStr := secNew.Key(keyEnUs.Name()).String() - if oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%") { - fmt.Printf("WARNING: locale %s [%s]%s has different number of arguments, skipping\n", path, secEnUS.Name(), keyEnUs.Name()) - fmt.Printf("\told: %s\n", oldStr) - fmt.Printf("\tnew: %s\n", newStr) - fmt.Println("---- ") + broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%") + broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n") + if broken { + brokenWarned[secOld.Name()+"."+keyEnUs.Name()] = true + fmt.Println("----") + fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name()) + fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n")) + fmt.Printf("\tnew: %s\n", strings.ReplaceAll(newStr, "\n", "\\n")) continue } secOld.Key(keyEnUs.Name()).SetValue(newStr) @@ -90,4 +94,25 @@ func main() { } mustNoErr(iniOld.SaveTo(path)) } + + fmt.Println("========") + + for path, iniNew := range inisNew { + for _, sec := range iniNew.Sections() { + for _, key := range sec.Keys() { + str := sec.Key(key.Name()).String() + broken := strings.Contains(str, "\n") + broken = broken || strings.HasPrefix(str, "`") != strings.HasSuffix(str, "`") + broken = broken || strings.HasPrefix(str, "\"`") + broken = broken || strings.HasPrefix(str, "`\"") + broken = broken || strings.Count(str, `"`)%2 == 1 + broken = broken || strings.Count(str, "`")%2 == 1 + if broken && !brokenWarned[sec.Name()+"."+key.Name()] { + fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name()) + fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n")) + fmt.Println("----") + } + } + } + } } |