Merge branch 'master' into browser-flag

This commit is contained in:
Tully Robinson
2014-08-06 23:01:35 +10:00
7 changed files with 87 additions and 26 deletions

File diff suppressed because one or more lines are too long

View File

@@ -114,7 +114,7 @@ translate() {
transifex() { transifex() {
pushd gui pushd gui
go run ../cmd/transifexdl/main.go > valid-langs.js go run ../cmd/transifexdl/main.go
popd popd
assets assets
} }

View File

@@ -9,10 +9,13 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
"regexp"
"sort" "sort"
"strings"
) )
type stat struct { type stat struct {
@@ -31,6 +34,12 @@ func main() {
log.Fatal("Need environment variables TRANSIFEX_USER and TRANSIFEX_PASS") log.Fatal("Need environment variables TRANSIFEX_USER and TRANSIFEX_PASS")
} }
curValidLangs := map[string]bool{}
for _, lang := range loadValidLangs() {
curValidLangs[lang] = true
}
log.Println(curValidLangs)
resp := req("https://www.transifex.com/api/2/project/syncthing/resource/gui/stats") resp := req("https://www.transifex.com/api/2/project/syncthing/resource/gui/stats")
var stats map[string]stat var stats map[string]stat
@@ -43,10 +52,12 @@ func main() {
var langs []string var langs []string
for code, stat := range stats { for code, stat := range stats {
shortCode := code[:2] shortCode := code[:2]
if pct := 100 * stat.Translated / (stat.Translated + stat.Untranslated); pct < 95 { if !curValidLangs[shortCode] {
log.Printf("Skipping language %q (too low completion ratio %d%%)", shortCode, pct) if pct := 100 * stat.Translated / (stat.Translated + stat.Untranslated); pct < 95 {
os.Remove("lang-" + shortCode + ".json") log.Printf("Skipping language %q (too low completion ratio %d%%)", shortCode, pct)
continue os.Remove("lang-" + shortCode + ".json")
continue
}
} }
langs = append(langs, shortCode) langs = append(langs, shortCode)
@@ -72,9 +83,18 @@ func main() {
fd.Close() fd.Close()
} }
saveValidLangs(langs)
}
func saveValidLangs(langs []string) {
sort.Strings(langs) sort.Strings(langs)
fmt.Print("var validLangs = ") fd, err := os.Create("valid-langs.js")
json.NewEncoder(os.Stdout).Encode(langs) if err != nil {
log.Fatal(err)
}
fmt.Fprint(fd, "var validLangs = ")
json.NewEncoder(fd).Encode(langs)
fd.Close()
} }
func userPass() (string, string) { func userPass() (string, string) {
@@ -97,3 +117,27 @@ func req(url string) *http.Response {
} }
return resp return resp
} }
func loadValidLangs() []string {
fd, err := os.Open("valid-langs.js")
if err != nil {
log.Fatal(err)
}
defer fd.Close()
bs, err := ioutil.ReadAll(fd)
if err != nil {
log.Fatal(err)
}
var langs []string
exp := regexp.MustCompile(`\[([a-z",]+)\]`)
if matches := exp.FindSubmatch(bs); len(matches) == 2 {
langs = strings.Split(string(matches[1]), ",")
for i := range langs {
// Remove quotes
langs[i] = langs[i][1 : len(langs[i])-1]
}
}
return langs
}

View File

@@ -10,12 +10,14 @@ import (
"encoding/json" "encoding/json"
"log" "log"
"os" "os"
"regexp"
"strings" "strings"
"code.google.com/p/go.net/html" "code.google.com/p/go.net/html"
) )
var trans = make(map[string]string) var trans = make(map[string]string)
var attrRe = regexp.MustCompile(`\{\{'([^']+)'\s+\|\s+translate\}\}`)
func generalNode(n *html.Node) { func generalNode(n *html.Node) {
translate := false translate := false
@@ -24,6 +26,10 @@ func generalNode(n *html.Node) {
if a.Key == "translate" { if a.Key == "translate" {
translate = true translate = true
break break
} else {
if matches := attrRe.FindStringSubmatch(a.Val); len(matches) == 2 {
translation(matches[1])
}
} }
} }
} else if n.Type == html.TextNode { } else if n.Type == html.TextNode {
@@ -44,12 +50,7 @@ func generalNode(n *html.Node) {
func inTranslate(n *html.Node) { func inTranslate(n *html.Node) {
if n.Type == html.TextNode { if n.Type == html.TextNode {
v := strings.TrimSpace(n.Data) translation(n.Data)
if _, ok := trans[v]; !ok {
av := strings.Replace(v, "{%", "{{", -1)
av = strings.Replace(av, "%}", "}}", -1)
trans[v] = av
}
} else { } else {
log.Println("translate node with non-text child <") log.Println("translate node with non-text child <")
log.Println(n) log.Println(n)
@@ -60,6 +61,15 @@ func inTranslate(n *html.Node) {
} }
} }
func translation(v string) {
v = strings.TrimSpace(v)
if _, ok := trans[v]; !ok {
av := strings.Replace(v, "{%", "{{", -1)
av = strings.Replace(av, "%}", "}}", -1)
trans[v] = av
}
}
func main() { func main() {
fd, err := os.Open(os.Args[1]) fd, err := os.Open(os.Args[1])
if err != nil { if err != nil {

View File

@@ -514,8 +514,6 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
$scope.restart = function () { $scope.restart = function () {
restarting = true; restarting = true;
$scope.restartingTitle = "Restarting"
$scope.restartingBody = "Syncthing is restarting."
$('#restarting').modal({backdrop: 'static', keyboard: false}); $('#restarting').modal({backdrop: 'static', keyboard: false});
$http.post(urlbase + '/restart'); $http.post(urlbase + '/restart');
$scope.configInSync = true; $scope.configInSync = true;
@@ -537,14 +535,13 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
}; };
$scope.upgrade = function () { $scope.upgrade = function () {
$scope.restartingTitle = "Upgrading" restarting = true;
$scope.restartingBody = "Syncthing is upgrading." $('#upgrading').modal({backdrop: 'static', keyboard: false});
$('#restarting').modal({backdrop: 'static', keyboard: false});
$http.post(urlbase + '/upgrade').success(function () { $http.post(urlbase + '/upgrade').success(function () {
restarting = true; $('#restarting').modal({backdrop: 'static', keyboard: false});
$scope.restartingBody = "Syncthing is restarting into the new version." $('#upgrading').modal('hide');
}).error(function () { }).error(function () {
$('#restarting').modal('hide'); $('#upgrading').modal('hide');
}); });
}; };

View File

@@ -391,8 +391,12 @@
<!-- Restarting modal --> <!-- Restarting modal -->
<modal id="restarting" icon="refresh" title="{{restartingTitle}}" status="info"> <modal id="restarting" icon="refresh" title="{{'Restarting' | translate}}" status="info">
<p>{{restartingBody}} <span translate>Please wait</span>&hellip;</p> <p><span translate>Syncthing is restarting.</span> <span translate>Please wait</span>...</p>
</modal>
<modal id="upgrading" icon="refresh" title="{{'Upgrading' | translate}}" status="info">
<p><span translate>Syncthing is upgrading.</span> <span translate>Please wait</span>...</p>
</modal> </modal>
<!-- Shutdown modal --> <!-- Shutdown modal -->

View File

@@ -11,6 +11,7 @@
"Bugs": "Bugs", "Bugs": "Bugs",
"CPU Utilization": "CPU Utilization", "CPU Utilization": "CPU Utilization",
"Close": "Close", "Close": "Close",
"Connection Error": "Connection Error",
"Copyright © 2014 Jakob Borg and the following Contributors:": "Copyright © 2014 Jakob Borg and the following Contributors:", "Copyright © 2014 Jakob Borg and the following Contributors:": "Copyright © 2014 Jakob Borg and the following Contributors:",
"Delete": "Delete", "Delete": "Delete",
"Disconnected": "Disconnected", "Disconnected": "Disconnected",
@@ -46,6 +47,7 @@
"Max Outstanding Requests": "Max Outstanding Requests", "Max Outstanding Requests": "Max Outstanding Requests",
"No": "No", "No": "No",
"Node ID": "Node ID", "Node ID": "Node ID",
"Node Identification": "Node Identification",
"Node Name": "Node Name", "Node Name": "Node Name",
"Notice": "Notice", "Notice": "Notice",
"OK": "OK", "OK": "OK",
@@ -65,6 +67,7 @@
"Rescan Interval (s)": "Rescan Interval (s)", "Rescan Interval (s)": "Rescan Interval (s)",
"Restart": "Restart", "Restart": "Restart",
"Restart Needed": "Restart Needed", "Restart Needed": "Restart Needed",
"Restarting": "Restarting",
"Save": "Save", "Save": "Save",
"Scanning": "Scanning", "Scanning": "Scanning",
"Select the nodes to share this repository with.": "Select the nodes to share this repository with.", "Select the nodes to share this repository with.": "Select the nodes to share this repository with.",
@@ -84,6 +87,8 @@
"Syncing": "Syncing", "Syncing": "Syncing",
"Syncthing has been shut down.": "Syncthing has been shut down.", "Syncthing has been shut down.": "Syncthing has been shut down.",
"Syncthing includes the following software or portions thereof:": "Syncthing includes the following software or portions thereof:", "Syncthing includes the following software or portions thereof:": "Syncthing includes the following software or portions thereof:",
"Syncthing is restarting.": "Syncthing is restarting.",
"Syncthing is upgrading.": "Syncthing is upgrading.",
"Syncthing seems to be down, or there is a problem with your Internet connection. Retrying…": "Syncthing seems to be down, or there is a problem with your Internet connection. Retrying…", "Syncthing seems to be down, or there is a problem with your Internet connection. Retrying…": "Syncthing seems to be down, or there is a problem with your Internet connection. Retrying…",
"The aggregated statistics are publicly available at {%url%}.": "The aggregated statistics are publicly available at {{url}}.", "The aggregated statistics are publicly available at {%url%}.": "The aggregated statistics are publicly available at {{url}}.",
"The configuration has been saved but not activated. Syncthing must restart to activate the new configuration.": "The configuration has been saved but not activated. Syncthing must restart to activate the new configuration.", "The configuration has been saved but not activated. Syncthing must restart to activate the new configuration.": "The configuration has been saved but not activated. Syncthing must restart to activate the new configuration.",
@@ -101,6 +106,7 @@
"Unknown": "Unknown", "Unknown": "Unknown",
"Up to Date": "Up to Date", "Up to Date": "Up to Date",
"Upgrade To {%version%}": "Upgrade To {{version}}", "Upgrade To {%version%}": "Upgrade To {{version}}",
"Upgrading": "Upgrading",
"Upload Rate": "Upload Rate", "Upload Rate": "Upload Rate",
"Usage": "Usage", "Usage": "Usage",
"Use Compression": "Use Compression", "Use Compression": "Use Compression",