0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-09 11:31:34 +01:00
gitea/build/backport-locales.go

116 lines
3.3 KiB
Go
Raw Normal View History

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
//go:build ignore
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/setting"
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
)
func main() {
if len(os.Args) != 2 {
println("usage: backport-locales <to-ref>")
println("eg: backport-locales release/v1.19")
os.Exit(1)
}
mustNoErr := func(err error) {
if err != nil {
panic(err)
}
}
collectInis := func(ref string) map[string]setting.ConfigProvider {
inis := map[string]setting.ConfigProvider{}
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
err := filepath.WalkDir("options/locale", func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || !strings.HasSuffix(d.Name(), ".ini") {
return nil
}
cfg, err := setting.NewConfigProviderForLocale(path)
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
mustNoErr(err)
inis[path] = cfg
fmt.Printf("collecting: %s @ %s\n", path, ref)
return nil
})
mustNoErr(err)
return inis
}
// collect new locales from current working directory
inisNew := collectInis("HEAD")
// switch to the target ref, and collect the old locales
cmd := exec.Command("git", "checkout", os.Args[1])
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
mustNoErr(cmd.Run())
inisOld := collectInis(os.Args[1])
// 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 := make(container.Set[string])
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
for path, iniOld := range inisOld {
if iniOld == enUsOld {
continue
}
iniNew := inisNew[path]
if iniNew == nil {
continue
}
for _, secEnUS := range enUsOld.Sections() {
secOld := iniOld.Section(secEnUS.Name())
secNew := iniNew.Section(secEnUS.Name())
for _, keyEnUs := range secEnUS.Keys() {
if secNew.HasKey(keyEnUs.Name()) {
oldStr := secOld.Key(keyEnUs.Name()).String()
newStr := secNew.Key(keyEnUs.Name()).String()
broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%")
broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n")
if broken {
brokenWarned.Add(secOld.Name() + "." + keyEnUs.Name())
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"))
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
continue
}
secOld.Key(keyEnUs.Name()).SetValue(newStr)
}
}
}
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.Contains(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("----")
}
}
}
}
A tool to help to backport locales, changes source strings to fix other broken translations (#23633) It use old en-US locales as reference, fill the old other locales with new locales. ---- ## More broken translations Many translations are still broken. The reason is: at the last time restoring the ini to crowdin, many semicolon are treated as comments. Two kinds of broken strings: ### Some translations can be re-translated <details> ``` skipping options/locale/locale_si-LK.ini org teams.add_nonexistent_repo skipping options/locale/locale_tr-TR.ini repo commits.search.tooltip skipping options/locale/locale_es-ES.ini repo settings.trust_model.committer.desc skipping options/locale/locale_es-ES.ini admin dashboard.new_version_hint skipping options/locale/locale_pt-PT.ini org teams.add_nonexistent_repo skipping options/locale/locale_hu-HU.ini install require_sign_in_view_popup skipping options/locale/locale_hu-HU.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini repo migrate.invalid_local_path skipping options/locale/locale_id-ID.ini org teams.add_nonexistent_repo skipping options/locale/locale_de-DE.ini repo settings.protect_protected_file_patterns_desc ``` </details> So this PR also does some small changes on them, to trigger the re-translation. ### The `locale_el-GR.ini` contains many broken tranlsations I guess we should reset them from crowdin side, then translators can re-translate them. ---- Update: in latest main, the strings have been fixed. ## TODO Update: the el-GR translators have done great job and fixes these broken translations. <details> Merge this PR ASAP and upload `locale_el-GR.ini` to crowdin to remove broken strings. Out-dated, fixed in main. ![image](https://user-images.githubusercontent.com/2114189/226954531-36e14527-278a-41a1-8ddb-2b2b27bfc746.png) </details> --------- Co-authored-by: delvh <dev.lh@web.de>
2023-03-23 18:27:03 +01:00
}