From 3e3954eb3849b224b5b7cfac4c155f395d395833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Wed, 20 Oct 2021 19:44:38 +0200 Subject: [PATCH] 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. --- gui/default/assets/lang/lang-de.json | 4 ++++ gui/default/assets/lang/lang-en.json | 4 ++++ .../syncthing/core/syncthingController.js | 11 ++++++++--- script/translate.go | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gui/default/assets/lang/lang-de.json b/gui/default/assets/lang/lang-de.json index c53328fbc..ff6e4188d 100644 --- a/gui/default/assets/lang/lang-de.json +++ b/gui/default/assets/lang/lang-de.json @@ -436,6 +436,10 @@ "full documentation": "Komplette Dokumentation", "items": "Elemente", "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 \"{%folderlabel%}\" ({%folder%}).": "{{device}} möchte den Ordner \"{{folderlabel}}\" ({{folder}}) teilen.", "{%reintroducer%} might reintroduce this device.": "{{reintroducer}} könnte dieses Gerät wieder einführen." diff --git a/gui/default/assets/lang/lang-en.json b/gui/default/assets/lang/lang-en.json index 5930678ce..11e0a3ccc 100644 --- a/gui/default/assets/lang/lang-en.json +++ b/gui/default/assets/lang/lang-en.json @@ -436,6 +436,10 @@ "full documentation": "full documentation", "items": "items", "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 \"{%folderlabel%}\" ({%folder%}).": "{{device}} wants to share folder \"{{folderlabel}}\" ({{folder}}).", "{%reintroducer%} might reintroduce this device.": "{{reintroducer}} might reintroduce this device." diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index 21293f08e..8e91fda41 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -2822,9 +2822,14 @@ angular.module('syncthing.core') }; $scope.themeName = function (theme) { - return theme.replace('-', ' ').replace(/(?:^|\s)\S/g, function (a) { - return a.toUpperCase(); - }); + var translation = $translate.instant("theme-name-" + theme); + 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 () { diff --git a/script/translate.go b/script/translate.go index d311f000b..5f9f0ada3 100644 --- a/script/translate.go +++ b/script/translate.go @@ -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 {