gui, script: Parse JS files for translation values (fixes #7845) (#7846)

This commit is contained in:
Simon Frei 2021-07-23 14:24:08 +02:00 committed by GitHub
parent cb26552440
commit 7ec76095e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 6 deletions

View File

@ -94,6 +94,7 @@
"Discovered": "Discovered", "Discovered": "Discovered",
"Discovery": "Discovery", "Discovery": "Discovery",
"Discovery Failures": "Discovery Failures", "Discovery Failures": "Discovery Failures",
"Discovery Status": "Discovery Status",
"Dismiss": "Dismiss", "Dismiss": "Dismiss",
"Do not add it to the ignore list, so this notification may recur.": "Do not add it to the ignore list, so this notification may recur.", "Do not add it to the ignore list, so this notification may recur.": "Do not add it to the ignore list, so this notification may recur.",
"Do not restore": "Do not restore", "Do not restore": "Do not restore",
@ -121,6 +122,7 @@
"Error": "Error", "Error": "Error",
"External File Versioning": "External File Versioning", "External File Versioning": "External File Versioning",
"Failed Items": "Failed Items", "Failed Items": "Failed Items",
"Failed to load ignore patterns.": "Failed to load ignore patterns.",
"Failed to setup, retrying": "Failed to setup, retrying", "Failed to setup, retrying": "Failed to setup, retrying",
"Failure to connect to IPv6 servers is expected if there is no IPv6 connectivity.": "Failure to connect to IPv6 servers is expected if there is no IPv6 connectivity.", "Failure to connect to IPv6 servers is expected if there is no IPv6 connectivity.": "Failure to connect to IPv6 servers is expected if there is no IPv6 connectivity.",
"File Pull Order": "File Pull Order", "File Pull Order": "File Pull Order",
@ -178,6 +180,8 @@
"Latest Change": "Latest Change", "Latest Change": "Latest Change",
"Learn more": "Learn more", "Learn more": "Learn more",
"Limit": "Limit", "Limit": "Limit",
"Listener Failures": "Listener Failures",
"Listener Status": "Listener Status",
"Listeners": "Listeners", "Listeners": "Listeners",
"Loading data...": "Loading data...", "Loading data...": "Loading data...",
"Loading...": "Loading...", "Loading...": "Loading...",
@ -216,6 +220,7 @@
"Out of Sync": "Out of Sync", "Out of Sync": "Out of Sync",
"Out of Sync Items": "Out of Sync Items", "Out of Sync Items": "Out of Sync Items",
"Outgoing Rate Limit (KiB/s)": "Outgoing Rate Limit (KiB/s)", "Outgoing Rate Limit (KiB/s)": "Outgoing Rate Limit (KiB/s)",
"Override": "Override",
"Override Changes": "Override Changes", "Override Changes": "Override Changes",
"Path": "Path", "Path": "Path",
"Path to the folder on the local computer. Will be created if it does not exist. The tilde character (~) can be used as a shortcut for": "Path to the folder on the local computer. Will be created if it does not exist. The tilde character (~) can be used as a shortcut for", "Path to the folder on the local computer. Will be created if it does not exist. The tilde character (~) can be used as a shortcut for": "Path to the folder on the local computer. Will be created if it does not exist. The tilde character (~) can be used as a shortcut for",
@ -265,6 +270,7 @@
"Resume": "Resume", "Resume": "Resume",
"Resume All": "Resume All", "Resume All": "Resume All",
"Reused": "Reused", "Reused": "Reused",
"Revert": "Revert",
"Revert Local Changes": "Revert Local Changes", "Revert Local Changes": "Revert Local Changes",
"Save": "Save", "Save": "Save",
"Scan Time Remaining": "Scan Time Remaining", "Scan Time Remaining": "Scan Time Remaining",

View File

@ -9,6 +9,7 @@
package main package main
import ( import (
"bufio"
"encoding/json" "encoding/json"
"log" "log"
"os" "os"
@ -22,6 +23,7 @@ import (
var trans = make(map[string]string) var trans = make(map[string]string)
var attrRe = regexp.MustCompile(`\{\{\s*'([^']+)'\s+\|\s+translate\s*\}\}`) var attrRe = regexp.MustCompile(`\{\{\s*'([^']+)'\s+\|\s+translate\s*\}\}`)
var attrReCond = regexp.MustCompile(`\{\{.+\s+\?\s+'([^']+)'\s+:\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 // exceptions to the untranslated text warning
var noStringRe = regexp.MustCompile( var noStringRe = regexp.MustCompile(
@ -108,17 +110,27 @@ func walkerFor(basePath string) filepath.WalkFunc {
return err return err
} }
if filepath.Ext(name) == ".html" && info.Mode().IsRegular() { if !info.Mode().IsRegular() {
fd, err := os.Open(name) return nil
if err != nil { }
log.Fatal(err) 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) doc, err := html.Parse(fd)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fd.Close()
generalNode(doc, filepath.Base(name)) 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 return nil