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.
This commit is contained in:
André Colomb 2022-09-16 22:52:33 +02:00 committed by GitHub
parent 39d3424e34
commit 698346edc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -124,12 +124,17 @@
"Enable NAT traversal": "Enable NAT traversal",
"Enable Relaying": "Enable Relaying",
"Enabled": "Enabled",
"Enables sending extended attributes to other devices, and applying incoming extended attributes. May require running with elevated privileges.": "Enables sending extended attributes to other devices, and applying incoming extended attributes. May require running with elevated privileges.",
"Enables sending extended attributes to other devices, but not applying incoming extended attributes. This can have a significant performance impact. Always enabled when \"Sync Extended Attributes\" is enabled.": "Enables sending extended attributes to other devices, but not applying incoming extended attributes. This can have a significant performance impact. Always enabled when \"Sync Extended Attributes\" is enabled.",
"Enables sending ownership information to other devices, and applying incoming ownership information. Typically requires running with elevated privileges.": "Enables sending ownership information to other devices, and applying incoming ownership information. Typically requires running with elevated privileges.",
"Enables sending ownership to other devices, but not applying incoming ownership information. This can have a significant performance impact. Always enabled when \"Sync Ownership\" is enabled.": "Enables sending ownership to other devices, but not applying incoming ownership information. This can have a significant performance impact. Always enabled when \"Sync Ownership\" is enabled.",
"Enter a non-negative number (e.g., \"2.35\") and select a unit. Percentages are as part of the total disk size.": "Enter a non-negative number (e.g., \"2.35\") and select a unit. Percentages are as part of the total disk size.",
"Enter a non-privileged port number (1024 - 65535).": "Enter a non-privileged port number (1024 - 65535).",
"Enter comma separated (\"tcp://ip:port\", \"tcp://host:port\") addresses or \"dynamic\" to perform automatic discovery of the address.": "Enter comma separated (\"tcp://ip:port\", \"tcp://host:port\") addresses or \"dynamic\" to perform automatic discovery of the address.",
"Enter ignore patterns, one per line.": "Enter ignore patterns, one per line.",
"Enter up to three octal digits.": "Enter up to three octal digits.",
"Error": "Error",
"Extended Attributes": "Extended Attributes",
"External": "External",
"External File Versioning": "External File Versioning",
"Failed Items": "Failed Items",
@ -244,6 +249,7 @@
"Outgoing Rate Limit (KiB/s)": "Outgoing Rate Limit (KiB/s)",
"Override": "Override",
"Override Changes": "Override Changes",
"Ownership": "Ownership",
"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 where versions should be stored (leave empty for the default .stversions directory in the shared folder).": "Path where versions should be stored (leave empty for the default .stversions directory in the shared folder).",
@ -304,7 +310,9 @@
"Select latest version": "Select latest version",
"Select oldest version": "Select oldest version",
"Send \u0026 Receive": "Send \u0026 Receive",
"Send Extended Attributes": "Send Extended Attributes",
"Send Only": "Send Only",
"Send Ownership": "Send Ownership",
"Set Ignores on Added Folder": "Set Ignores on Added Folder",
"Settings": "Settings",
"Share": "Share",
@ -342,6 +350,8 @@
"Stores and syncs only encrypted data. Folders on all connected devices need to be set up with the same password or be of type \"{%receiveEncrypted%}\" too.": "Stores and syncs only encrypted data. Folders on all connected devices need to be set up with the same password or be of type \"{{receiveEncrypted}}\" too.",
"Support": "Support",
"Support Bundle": "Support Bundle",
"Sync Extended Attributes": "Sync Extended Attributes",
"Sync Ownership": "Sync Ownership",
"Sync Protocol Listen Addresses": "Sync Protocol Listen Addresses",
"Sync Status": "Sync Status",
"Syncing": "Syncing",

View File

@ -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])
}
}
}
}