gui: Translate theme names in settings (#8006)

Add each subdirectory of the guiDir as a translation candidate string.
The key is prefixed with "theme-name-" and the default English
translation corresponds to the directory name turned to title case.
Disable the automatic name mangling in the GUI JS code in favor of
just looking up the translation.
This commit is contained in:
André Colomb
2021-10-20 19:44:38 +02:00
committed by GitHub
parent 517667c590
commit 3e3954eb38
4 changed files with 33 additions and 3 deletions

View File

@@ -138,6 +138,22 @@ func walkerFor(basePath string) filepath.WalkFunc {
}
}
func collectThemes(basePath string) {
files, err := os.ReadDir(basePath)
if err != nil {
log.Fatal(err)
}
for _, f := range files {
if f.IsDir() {
key := "theme-name-" + f.Name()
if _, ok := trans[key]; !ok {
name := strings.Title(f.Name())
trans[key] = name
}
}
}
}
func main() {
fd, err := os.Open(os.Args[1])
if err != nil {
@@ -152,6 +168,7 @@ func main() {
var guiDir = os.Args[2]
filepath.Walk(guiDir, walkerFor(guiDir))
collectThemes(guiDir)
bs, err := json.MarshalIndent(trans, "", " ")
if err != nil {