Merge branch 'master' into browser-flag

This commit is contained in:
Tully Robinson 2014-08-06 23:01:35 +10:00
commit c45b18cc75
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() {
pushd gui
go run ../cmd/transifexdl/main.go > valid-langs.js
go run ../cmd/transifexdl/main.go
popd
assets
}

View File

@ -9,10 +9,13 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"sort"
"strings"
)
type stat struct {
@ -31,6 +34,12 @@ func main() {
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")
var stats map[string]stat
@ -43,10 +52,12 @@ func main() {
var langs []string
for code, stat := range stats {
shortCode := code[:2]
if pct := 100 * stat.Translated / (stat.Translated + stat.Untranslated); pct < 95 {
log.Printf("Skipping language %q (too low completion ratio %d%%)", shortCode, pct)
os.Remove("lang-" + shortCode + ".json")
continue
if !curValidLangs[shortCode] {
if pct := 100 * stat.Translated / (stat.Translated + stat.Untranslated); pct < 95 {
log.Printf("Skipping language %q (too low completion ratio %d%%)", shortCode, pct)
os.Remove("lang-" + shortCode + ".json")
continue
}
}
langs = append(langs, shortCode)
@ -72,9 +83,18 @@ func main() {
fd.Close()
}
saveValidLangs(langs)
}
func saveValidLangs(langs []string) {
sort.Strings(langs)
fmt.Print("var validLangs = ")
json.NewEncoder(os.Stdout).Encode(langs)
fd, err := os.Create("valid-langs.js")
if err != nil {
log.Fatal(err)
}
fmt.Fprint(fd, "var validLangs = ")
json.NewEncoder(fd).Encode(langs)
fd.Close()
}
func userPass() (string, string) {
@ -97,3 +117,27 @@ func req(url string) *http.Response {
}
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"
"log"
"os"
"regexp"
"strings"
"code.google.com/p/go.net/html"
)
var trans = make(map[string]string)
var attrRe = regexp.MustCompile(`\{\{'([^']+)'\s+\|\s+translate\}\}`)
func generalNode(n *html.Node) {
translate := false
@ -24,6 +26,10 @@ func generalNode(n *html.Node) {
if a.Key == "translate" {
translate = true
break
} else {
if matches := attrRe.FindStringSubmatch(a.Val); len(matches) == 2 {
translation(matches[1])
}
}
}
} else if n.Type == html.TextNode {
@ -44,12 +50,7 @@ func generalNode(n *html.Node) {
func inTranslate(n *html.Node) {
if n.Type == html.TextNode {
v := strings.TrimSpace(n.Data)
if _, ok := trans[v]; !ok {
av := strings.Replace(v, "{%", "{{", -1)
av = strings.Replace(av, "%}", "}}", -1)
trans[v] = av
}
translation(n.Data)
} else {
log.Println("translate node with non-text child <")
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() {
fd, err := os.Open(os.Args[1])
if err != nil {

View File

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

View File

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

View File

@ -11,6 +11,7 @@
"Bugs": "Bugs",
"CPU Utilization": "CPU Utilization",
"Close": "Close",
"Connection Error": "Connection Error",
"Copyright © 2014 Jakob Borg and the following Contributors:": "Copyright © 2014 Jakob Borg and the following Contributors:",
"Delete": "Delete",
"Disconnected": "Disconnected",
@ -46,6 +47,7 @@
"Max Outstanding Requests": "Max Outstanding Requests",
"No": "No",
"Node ID": "Node ID",
"Node Identification": "Node Identification",
"Node Name": "Node Name",
"Notice": "Notice",
"OK": "OK",
@ -65,6 +67,7 @@
"Rescan Interval (s)": "Rescan Interval (s)",
"Restart": "Restart",
"Restart Needed": "Restart Needed",
"Restarting": "Restarting",
"Save": "Save",
"Scanning": "Scanning",
"Select the nodes to share this repository with.": "Select the nodes to share this repository with.",
@ -84,6 +87,8 @@
"Syncing": "Syncing",
"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 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…",
"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.",
@ -101,6 +106,7 @@
"Unknown": "Unknown",
"Up to Date": "Up to Date",
"Upgrade To {%version%}": "Upgrade To {{version}}",
"Upgrading": "Upgrading",
"Upload Rate": "Upload Rate",
"Usage": "Usage",
"Use Compression": "Use Compression",