Переглянути джерело

Fix translation in upgrading/restarting dialogs

Jakob Borg 11 роки тому
батько
коміт
68b1ffec19
5 змінених файлів з 33 додано та 16 видалено
  1. 0 0
      auto/gui.files.go
  2. 16 6
      cmd/translate/main.go
  3. 5 8
      gui/app.js
  4. 6 2
      gui/index.html
  5. 6 0
      gui/lang-en.json

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
auto/gui.files.go


+ 16 - 6
cmd/translate/main.go

@@ -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 {

+ 5 - 8
gui/app.js

@@ -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');
         });
     };
 

+ 6 - 2
gui/index.html

@@ -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 -->

+ 6 - 0
gui/lang-en.json

@@ -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",

Деякі файли не було показано, через те що забагато файлів було змінено