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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View File

@ -436,6 +436,10 @@
"full documentation": "Komplette Dokumentation", "full documentation": "Komplette Dokumentation",
"items": "Elemente", "items": "Elemente",
"seconds": "Sekunden", "seconds": "Sekunden",
"theme-name-black": "Schwarz",
"theme-name-dark": "Dunkel",
"theme-name-default": "Standard",
"theme-name-light": "Hell",
"{%device%} wants to share folder \"{%folder%}\".": "{{device}} möchte den Ordner \"{{folder}}\" teilen.", "{%device%} wants to share folder \"{%folder%}\".": "{{device}} möchte den Ordner \"{{folder}}\" teilen.",
"{%device%} wants to share folder \"{%folderlabel%}\" ({%folder%}).": "{{device}} möchte den Ordner \"{{folderlabel}}\" ({{folder}}) teilen.", "{%device%} wants to share folder \"{%folderlabel%}\" ({%folder%}).": "{{device}} möchte den Ordner \"{{folderlabel}}\" ({{folder}}) teilen.",
"{%reintroducer%} might reintroduce this device.": "{{reintroducer}} könnte dieses Gerät wieder einführen." "{%reintroducer%} might reintroduce this device.": "{{reintroducer}} könnte dieses Gerät wieder einführen."

View File

@ -436,6 +436,10 @@
"full documentation": "full documentation", "full documentation": "full documentation",
"items": "items", "items": "items",
"seconds": "seconds", "seconds": "seconds",
"theme-name-black": "Black",
"theme-name-dark": "Dark",
"theme-name-default": "Default",
"theme-name-light": "Light",
"{%device%} wants to share folder \"{%folder%}\".": "{{device}} wants to share folder \"{{folder}}\".", "{%device%} wants to share folder \"{%folder%}\".": "{{device}} wants to share folder \"{{folder}}\".",
"{%device%} wants to share folder \"{%folderlabel%}\" ({%folder%}).": "{{device}} wants to share folder \"{{folderlabel}}\" ({{folder}}).", "{%device%} wants to share folder \"{%folderlabel%}\" ({%folder%}).": "{{device}} wants to share folder \"{{folderlabel}}\" ({{folder}}).",
"{%reintroducer%} might reintroduce this device.": "{{reintroducer}} might reintroduce this device." "{%reintroducer%} might reintroduce this device.": "{{reintroducer}} might reintroduce this device."

View File

@ -2822,9 +2822,14 @@ angular.module('syncthing.core')
}; };
$scope.themeName = function (theme) { $scope.themeName = function (theme) {
return theme.replace('-', ' ').replace(/(?:^|\s)\S/g, function (a) { var translation = $translate.instant("theme-name-" + theme);
return a.toUpperCase(); if (translation.startsWith("theme-name-")) {
}); // Fall back to simple Title Casing on missing translation
translation = theme.toLowerCase().replace(/(?:^|\s)\S/g, function (a) {
return a.toUpperCase();
});
}
return translation;
}; };
$scope.modalLoaded = function () { $scope.modalLoaded = function () {

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() { func main() {
fd, err := os.Open(os.Args[1]) fd, err := os.Open(os.Args[1])
if err != nil { if err != nil {
@ -152,6 +168,7 @@ func main() {
var guiDir = os.Args[2] var guiDir = os.Args[2]
filepath.Walk(guiDir, walkerFor(guiDir)) filepath.Walk(guiDir, walkerFor(guiDir))
collectThemes(guiDir)
bs, err := json.MarshalIndent(trans, "", " ") bs, err := json.MarshalIndent(trans, "", " ")
if err != nil { if err != nil {