build: Improve translation script (fixes #6943) (#6944)

This commit is contained in:
Simon Frei 2020-08-30 08:01:46 +02:00 committed by GitHub
parent 563cea0dbe
commit 44bf8cfd27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -91,6 +91,8 @@
"Downloaded": "Downloaded", "Downloaded": "Downloaded",
"Downloading": "Downloading", "Downloading": "Downloading",
"Edit": "Edit", "Edit": "Edit",
"Edit Device": "Edit Device",
"Edit Folder": "Edit Folder",
"Editing {%path%}.": "Editing {{path}}.", "Editing {%path%}.": "Editing {{path}}.",
"Enable Crash Reporting": "Enable Crash Reporting", "Enable Crash Reporting": "Enable Crash Reporting",
"Enable NAT traversal": "Enable NAT traversal", "Enable NAT traversal": "Enable NAT traversal",
@ -373,6 +375,7 @@
"You have unsaved changes. Do you really want to discard them?": "You have unsaved changes. Do you really want to discard them?", "You have unsaved changes. Do you really want to discard them?": "You have unsaved changes. Do you really want to discard them?",
"You must keep at least one version.": "You must keep at least one version.", "You must keep at least one version.": "You must keep at least one version.",
"days": "days", "days": "days",
"directories": "directories",
"files": "files", "files": "files",
"full documentation": "full documentation", "full documentation": "full documentation",
"items": "items", "items": "items",

View File

@ -21,13 +21,14 @@ import (
var trans = make(map[string]string) var trans = make(map[string]string)
var attrRe = regexp.MustCompile(`\{\{'([^']+)'\s+\|\s+translate\}\}`) var attrRe = regexp.MustCompile(`\{\{'([^']+)'\s+\|\s+translate\}\}`)
var attrReCond = regexp.MustCompile(`\{\{.+\s+\?\s+'([^']+)'\s+:\s+'([^']+)'\s+\|\s+translate\}\}`)
// exceptions to the untranslated text warning // exceptions to the untranslated text warning
var noStringRe = regexp.MustCompile( var noStringRe = regexp.MustCompile(
`^((\W*\{\{.*?\}\} ?.?\/?.?(bps)?\W*)+(\.stignore)?|[^a-zA-Z]+.?[^a-zA-Z]*|[kMGT]?B|Twitter|JS\W?|DEV|https?://\S+)$`) `^((\W*\{\{.*?\}\} ?.?\/?.?(bps)?\W*)+(\.stignore)?|[^a-zA-Z]+.?[^a-zA-Z]*|[kMGT]?B|Twitter|JS\W?|DEV|https?://\S+)$`)
// exceptions to the untranslated text warning specific to aboutModalView.html // exceptions to the untranslated text warning specific to aboutModalView.html
var aboutRe = regexp.MustCompile(`^([^/]+/[^/]+|(The Go Pro|Font Awesome ).+)$`) var aboutRe = regexp.MustCompile(`^([^/]+/[^/]+|(The Go Pro|Font Awesome ).+|Build \{\{.+\}\}|Copyright .+ the Syncthing Authors\.)$`)
func generalNode(n *html.Node, filename string) { func generalNode(n *html.Node, filename string) {
translate := false translate := false
@ -46,9 +47,13 @@ func generalNode(n *html.Node, filename string) {
// copyright notices of other projects // copyright notices of other projects
return return
} else { } else {
if matches := attrRe.FindStringSubmatch(a.Val); len(matches) == 2 { for _, matches := range attrRe.FindAllStringSubmatch(a.Val, -1) {
translation(matches[1]) translation(matches[1])
} }
for _, matches := range attrReCond.FindAllStringSubmatch(a.Val, -1) {
translation(matches[1])
translation(matches[2])
}
if a.Key == "data-content" && if a.Key == "data-content" &&
!noStringRe.MatchString(a.Val) { !noStringRe.MatchString(a.Val) {
log.Println("Untranslated data-content string (" + filename + "):") log.Println("Untranslated data-content string (" + filename + "):")