(n *html.Node, filename string)
| 42 | var aboutRe = regexp.MustCompile(`^([^/]+/[^/]+|(The Go Pro|Font Awesome ).+|Build \{\{.+\}\}|Copyright .+ the Syncthing Authors\.)$`) |
| 43 | |
| 44 | func generalNode(n *html.Node, filename string) { |
| 45 | translate := false |
| 46 | translationId := "" |
| 47 | if n.Type == html.ElementNode { |
| 48 | if n.Data == "translate" { // for <translate>Text</translate> |
| 49 | translate = true |
| 50 | } else if n.Data == "style" || n.Data == "noscript" { |
| 51 | return |
| 52 | } else { |
| 53 | for _, a := range n.Attr { |
| 54 | if a.Key == "translate" { |
| 55 | translate = true |
| 56 | translationId = a.Val |
| 57 | } else if a.Key == "id" && (a.Val == "contributor-list" || |
| 58 | a.Val == "copyright-notices") { |
| 59 | // Don't translate a list of names and |
| 60 | // copyright notices of other projects |
| 61 | return |
| 62 | } else { |
| 63 | for _, matches := range attrRe.FindAllStringSubmatch(a.Val, -1) { |
| 64 | translation("", matches[1]) |
| 65 | } |
| 66 | for _, matches := range attrReCond.FindAllStringSubmatch(a.Val, -1) { |
| 67 | translation("", matches[1]) |
| 68 | translation("", matches[2]) |
| 69 | } |
| 70 | if a.Key == "data-content" && |
| 71 | !noStringRe.MatchString(a.Val) { |
| 72 | log.Println("Untranslated data-content string (" + filename + "):") |
| 73 | log.Print("\t" + a.Val) |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } else if n.Type == html.TextNode { |
| 79 | v := strings.TrimSpace(n.Data) |
| 80 | if len(v) > 1 && !noStringRe.MatchString(v) && |
| 81 | !(filename == "aboutModalView.html" && aboutRe.MatchString(v)) && |
| 82 | !(filename == "logbar.html" && (v == "warn" || v == "errors")) { |
| 83 | log.Println("Untranslated text node (" + filename + "):") |
| 84 | log.Print("\t" + v) |
| 85 | } |
| 86 | } |
| 87 | for c := n.FirstChild; c != nil; c = c.NextSibling { |
| 88 | if translate { |
| 89 | inTranslate(c, translationId, filename) |
| 90 | } else { |
| 91 | generalNode(c, filename) |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func inTranslate(n *html.Node, translationId string, filename string) { |
| 97 | if n.Type == html.TextNode { |
no test coverage detected