mirror of
https://github.com/octoleo/syncthing.git
synced 2024-10-02 03:29:02 +00:00
script, gui: Silence useless warnings in translation script
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4034 LGTM: AudriusButkevicius
This commit is contained in:
parent
5c27796471
commit
88dfd634e5
@ -18,7 +18,7 @@ Jakob Borg, Audrius Butkevicius, Alexander Graf, Anderson Mesquita, Antony Male,
|
|||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<p translate>Syncthing includes the following software or portions thereof:</p>
|
<p translate>Syncthing includes the following software or portions thereof:</p>
|
||||||
<ul class="list-unstyled two-columns">
|
<ul class="list-unstyled two-columns" id="copyright-notices">
|
||||||
<li><a href="http://getbootstrap.com/">Bootstrap</a>, Copyright © 2011-2016 Twitter, Inc.</li>
|
<li><a href="http://getbootstrap.com/">Bootstrap</a>, Copyright © 2011-2016 Twitter, Inc.</li>
|
||||||
<li><a href="https://angularjs.org/">AngularJS</a>, Copyright © 2010-2016 Google, Inc.</li>
|
<li><a href="https://angularjs.org/">AngularJS</a>, Copyright © 2010-2016 Google, Inc.</li>
|
||||||
<li><a href="https://github.com/bkaradzic/go-lz4">bkaradzic/go-lz4</a>, Copyright © 2011-2012 Branimir Karadzic, 2013 Damian Gryski.</li>
|
<li><a href="https://github.com/bkaradzic/go-lz4">bkaradzic/go-lz4</a>, Copyright © 2011-2012 Branimir Karadzic, 2013 Damian Gryski.</li>
|
||||||
|
@ -22,16 +22,30 @@ 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\}\}`)
|
||||||
|
|
||||||
|
// exceptions to the untranslated text warning
|
||||||
|
var noStringRe = regexp.MustCompile(
|
||||||
|
`^((\W*\{\{.*?\}\} ?.?\W*)+(\.stignore)?|[^a-zA-Z]+.?[^a-zA-Z]*|Twitter|JS\W?|DEV|https?://\S+)$`)
|
||||||
|
|
||||||
|
// exceptions to the untranslated text warning specific to aboutModalView.html
|
||||||
|
var aboutRe = regexp.MustCompile(`^([^/]+/[^/]+|(The Go Pro|Font Awesome ).+)$`)
|
||||||
|
|
||||||
func generalNode(n *html.Node, filename string) {
|
func generalNode(n *html.Node, filename string) {
|
||||||
translate := false
|
translate := false
|
||||||
if n.Type == html.ElementNode {
|
if n.Type == html.ElementNode {
|
||||||
if n.Data == "translate" { // for <translate>Text</translate>
|
if n.Data == "translate" { // for <translate>Text</translate>
|
||||||
translate = true
|
translate = true
|
||||||
|
} else if n.Data == "style" {
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
for _, a := range n.Attr {
|
for _, a := range n.Attr {
|
||||||
if a.Key == "translate" {
|
if a.Key == "translate" {
|
||||||
translate = true
|
translate = true
|
||||||
break
|
break
|
||||||
|
} else if a.Key == "id" && (a.Val == "contributor-list" ||
|
||||||
|
a.Val == "copyright-notices") {
|
||||||
|
// Don't translate a list of names and
|
||||||
|
// copyright notices of other projects
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
if matches := attrRe.FindStringSubmatch(a.Val); len(matches) == 2 {
|
if matches := attrRe.FindStringSubmatch(a.Val); len(matches) == 2 {
|
||||||
translation(matches[1])
|
translation(matches[1])
|
||||||
@ -41,7 +55,9 @@ func generalNode(n *html.Node, filename string) {
|
|||||||
}
|
}
|
||||||
} else if n.Type == html.TextNode {
|
} else if n.Type == html.TextNode {
|
||||||
v := strings.TrimSpace(n.Data)
|
v := strings.TrimSpace(n.Data)
|
||||||
if len(v) > 1 && !(strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}")) {
|
if len(v) > 1 && !noStringRe.MatchString(v) &&
|
||||||
|
!(filename == "aboutModalView.html" && aboutRe.MatchString(v)) &&
|
||||||
|
!(filename == "logbar.html" && (v == "warn" || v == "errors")) {
|
||||||
log.Println("Untranslated text node (" + filename + "):")
|
log.Println("Untranslated text node (" + filename + "):")
|
||||||
log.Print("\t" + v)
|
log.Print("\t" + v)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user