aboutsummaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorAndré Colomb <src@andre.colomb.de>2022-09-16 22:52:33 +0200
committerGitHub <noreply@github.com>2022-09-16 22:52:33 +0200
commit698346edc342c214d844a874c83a8fd6c9c6e18b (patch)
tree3439732cc4e2a5a4147254c6b72a23608848e06f /script
parent39d3424e34ae9c4636c4da53a075f744c6776567 (diff)
downloadsyncthing-698346edc342c214d844a874c83a8fd6c9c6e18b.tar.gz
syncthing-698346edc342c214d844a874c83a8fd6c9c6e18b.zip
script: Support single quotes in $translate.instant() parsing (#8542)
Duplicate the regular expression for single and double quotes. Support additional arguments (string substitution) in both variants. Simplify the translation string group matching by using a lazy quantifier instead of excluding the quote itself.
Diffstat (limited to 'script')
-rw-r--r--script/translate.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/script/translate.go b/script/translate.go
index 5f9f0ada3..15a82b524 100644
--- a/script/translate.go
+++ b/script/translate.go
@@ -24,7 +24,13 @@ 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\("([^"]+)"\)`)
+
+// Find both $translate.instant("…") and $translate.instant("…",…) in JS.
+// Consider single quote variants too.
+var jsRe = []*regexp.Regexp{
+ regexp.MustCompile(`\$translate\.instant\(\s*"(.+?)"(,.*|\s*)\)`),
+ regexp.MustCompile(`\$translate\.instant\(\s*'(.+?)'(,.*|\s*)\)`),
+}
// exceptions to the untranslated text warning
var noStringRe = regexp.MustCompile(
@@ -128,8 +134,10 @@ func walkerFor(basePath string) filepath.WalkFunc {
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])
+ for _, re := range jsRe {
+ for _, matches := range re.FindAllStringSubmatch(s.Text(), -1) {
+ translation(matches[1])
+ }
}
}
}