aboutsummaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorSimon Frei <freisim93@gmail.com>2021-07-23 14:24:08 +0200
committerGitHub <noreply@github.com>2021-07-23 14:24:08 +0200
commit7ec76095e6abd6c84b60c8cfe1f814188f1f9777 (patch)
treebea26982ea87a741a293c9c893dcd3ab0752b8e1 /script
parentcb26552440ebf60c366d2f9299e7d46e4850ddac (diff)
downloadsyncthing-7ec76095e6abd6c84b60c8cfe1f814188f1f9777.tar.gz
syncthing-7ec76095e6abd6c84b60c8cfe1f814188f1f9777.zip
gui, script: Parse JS files for translation values (fixes #7845) (#7846)
Diffstat (limited to 'script')
-rw-r--r--script/translate.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/script/translate.go b/script/translate.go
index 928068b5d..12a7def82 100644
--- a/script/translate.go
+++ b/script/translate.go
@@ -9,6 +9,7 @@
package main
import (
+ "bufio"
"encoding/json"
"log"
"os"
@@ -22,6 +23,7 @@ import (
var trans = make(map[string]string)
var attrRe = regexp.MustCompile(`\{\{\s*'([^']+)'\s+\|\s+translate\s*\}\}`)
var attrReCond = regexp.MustCompile(`\{\{.+\s+\?\s+'([^']+)'\s+:\s+'([^']+)'\s+\|\s+translate\s*\}\}`)
+var jsRe = regexp.MustCompile(`\$translate.instant\("([^"]+)"\)`)
// exceptions to the untranslated text warning
var noStringRe = regexp.MustCompile(
@@ -108,17 +110,27 @@ func walkerFor(basePath string) filepath.WalkFunc {
return err
}
- if filepath.Ext(name) == ".html" && info.Mode().IsRegular() {
- fd, err := os.Open(name)
- if err != nil {
- log.Fatal(err)
- }
+ if !info.Mode().IsRegular() {
+ return nil
+ }
+ fd, err := os.Open(name)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer fd.Close()
+ switch filepath.Ext(name) {
+ case ".html":
doc, err := html.Parse(fd)
if err != nil {
log.Fatal(err)
}
- fd.Close()
generalNode(doc, filepath.Base(name))
+ case ".js":
+ for s := bufio.NewScanner(fd); s.Scan(); {
+ for _, matches := range jsRe.FindAllStringSubmatch(s.Text(), -1) {
+ translation(matches[1])
+ }
+ }
}
return nil