Просмотр исходного кода

:art: 访问授权页支持多语言 https://github.com/siyuan-note/siyuan/issues/6824

Liang Ding 2 лет назад
Родитель
Сommit
f5943cac15

+ 5 - 1
app/appearance/langs/en_US.json

@@ -1007,6 +1007,10 @@
     "168": "Uploading data repo snapshot %s",
     "168": "Uploading data repo snapshot %s",
     "169": "Uploading data repo file %v",
     "169": "Uploading data repo file %v",
     "170": "Uploading data repo chunk %v",
     "170": "Uploading data repo chunk %v",
-    "171": "Uploading data repo reference %s"
+    "171": "Uploading data repo reference %s",
+    "172": " If you forget the authorization code, you can search<br>for <code class=\"b3-code\">accessAuthCode</code> in the workspace conf/conf.json",
+    "173": "Please enter the access auth code",
+    "174": "Unlock access",
+    "175": "Please enter the verification code"
   }
   }
 }
 }

+ 5 - 1
app/appearance/langs/es_ES.json

@@ -1007,6 +1007,10 @@
     "168": "Cargando instantánea de repositorio de datos %s",
     "168": "Cargando instantánea de repositorio de datos %s",
     "169": "Cargando archivo de repositorio de datos %v",
     "169": "Cargando archivo de repositorio de datos %v",
     "170": "Cargando fragmento de repositorio de datos %v",
     "170": "Cargando fragmento de repositorio de datos %v",
-    "171": "Cargando referencia de repositorio de datos %s"
+    "171": "Cargando referencia de repositorio de datos %s",
+    "172": "Si olvida el código de autorización, puede buscar <code class=\"b3-code\">accessAuthCode</code> en el archivo <br>conf/conf.json del espacio de trabajo",
+    "173": "Por favor ingrese el codigo de autorizacion de acceso",
+    "174": "Desbloquear acceso",
+    "175": "Por favor ingrese el código de verificación"
   }
   }
 }
 }

+ 5 - 1
app/appearance/langs/fr_FR.json

@@ -1007,6 +1007,10 @@
     "168": "Téléchargement de l'instantané du référentiel de données %s",
     "168": "Téléchargement de l'instantané du référentiel de données %s",
     "169": "Téléchargement du fichier de référentiel de données %v",
     "169": "Téléchargement du fichier de référentiel de données %v",
     "170": "Téléchargement du bloc de dépôt de données %v",
     "170": "Téléchargement du bloc de dépôt de données %v",
-    "171": "Téléchargement de la référence de référentiel de données %s"
+    "171": "Téléchargement de la référence de référentiel de données %s",
+    "172": "Si vous oubliez le code d'autorisation, vous pouvez rechercher <code class=\"b3-code\">accessAuthCode</code> dans le fichier <br>conf/conf.json de l'espace de travail",
+    "173": "Veuillez entrer le code d'autorisation d'accès",
+    "174": "Déverrouiller l'accès",
+    "175": "Veuillez entrer le code de vérification"
   }
   }
 }
 }

+ 5 - 1
app/appearance/langs/zh_CHT.json

@@ -1007,6 +1007,10 @@
     "168": "正在上傳數據倉庫快照 %s",
     "168": "正在上傳數據倉庫快照 %s",
     "169": "正在上傳數據倉庫文件 %v",
     "169": "正在上傳數據倉庫文件 %v",
     "170": "正在上傳數據倉庫分塊 %v",
     "170": "正在上傳數據倉庫分塊 %v",
-    "171": "正在上傳數據倉庫引用 %s"
+    "171": "正在上傳數據倉庫引用 %s",
+    "172": "如果你忘記了授權碼,可在工作空間<br>conf/conf.json 文件中搜索 <code class=\"b3-code\">accessAuthCode</code>",
+    "173": "請輸入訪問授權碼",
+    "174": "解鎖訪問",
+    "175": "請輸入驗證碼"
   }
   }
 }
 }

+ 5 - 1
app/appearance/langs/zh_CN.json

@@ -1007,6 +1007,10 @@
     "168": "正在上传数据仓库快照 %s",
     "168": "正在上传数据仓库快照 %s",
     "169": "正在上传数据仓库文件 %v",
     "169": "正在上传数据仓库文件 %v",
     "170": "正在上传数据仓库分块 %v",
     "170": "正在上传数据仓库分块 %v",
-    "171": "正在上传数据仓库引用 %s"
+    "171": "正在上传数据仓库引用 %s",
+    "172": "如果你忘记了授权码,可在工作空间<br>conf/conf.json 文件中搜索 <code class=\"b3-code\">accessAuthCode</code>",
+    "173": "请输入访问授权码",
+    "174": "解锁访问",
+    "175": "请输入验证码"
   }
   }
 }
 }

+ 5 - 6
app/stage/auth.html

@@ -157,16 +157,15 @@
 ">
 ">
 <div style="-webkit-app-region: drag;height: 32px;width: 100%;position: absolute;top: 0;"></div>
 <div style="-webkit-app-region: drag;height: 32px;width: 100%;position: absolute;top: 0;"></div>
 <div style="position: relative;z-index: 2;text-align: center">
 <div style="position: relative;z-index: 2;text-align: center">
-    <h1 style="margin-bottom: 48px;">思源 SiYuan</h1>
-    <input class="b3-text-filed" id="authCode" type="password" placeholder="授权码 Auth code"/><br>
+    <h1 style="margin-bottom: 48px;">SiYuan</h1>
+    <input class="b3-text-filed" id="authCode" type="password" placeholder="{{.l0}}"/><br>
     <div style="position: relative;width: 240px;margin: 8px auto 0;display: none">
     <div style="position: relative;width: 240px;margin: 8px auto 0;display: none">
         <img id="captchaImg" style="top: 1px;position: absolute;height: 28px;right: 1px;cursor: pointer">
         <img id="captchaImg" style="top: 1px;position: absolute;height: 28px;right: 1px;cursor: pointer">
-        <input id="captcha" class="b3-text-filed" placeholder="验证码 Captcha">
+        <input id="captcha" class="b3-text-filed" placeholder="{{.l3}}">
     </div>
     </div>
-    <button class="b3-button" onclick="submitAuth()">解锁 Unlock</button>
+    <button class="b3-button" onclick="submitAuth()">{{.l1}}</button>
     <div style="color: #5f6368;font-size: 14px;margin: 16px 0;">
     <div style="color: #5f6368;font-size: 14px;margin: 16px 0;">
-        如果你忘记了授权码,可在工作空间<br>conf/conf.json 文件中搜索 <code class="b3-code">accessAuthCode</code><br><br>
-        If you forget the authorization code, you can search<br>for <code class="b3-code">accessAuthCode</code> in the workspace conf/conf.json
+        {{.l2}}
     </div>
     </div>
     <button class="b3-button b3-button--white" onclick="exitSiYuan()">退出 Exit</button>
     <button class="b3-button b3-button--white" onclick="exitSiYuan()">退出 Exit</button>
 </div>
 </div>

+ 23 - 0
kernel/server/serve.go

@@ -17,7 +17,9 @@
 package server
 package server
 
 
 import (
 import (
+	"bytes"
 	"fmt"
 	"fmt"
+	"html/template"
 	"net"
 	"net"
 	"net/http"
 	"net/http"
 	"net/http/httputil"
 	"net/http/httputil"
@@ -267,6 +269,27 @@ func serveCheckAuth(c *gin.Context) {
 		c.Status(500)
 		c.Status(500)
 		return
 		return
 	}
 	}
+
+	tpl, err := template.New("auth").Parse(string(data))
+	if nil != err {
+		logging.LogErrorf("parse auth page failed: %s", err)
+		c.Status(500)
+		return
+	}
+
+	model := map[string]interface{}{
+		"l0": model.Conf.Language(173),
+		"l1": model.Conf.Language(174),
+		"l2": template.HTML(model.Conf.Language(172)),
+		"l3": model.Conf.Language(175),
+	}
+	buf := &bytes.Buffer{}
+	if err = tpl.Execute(buf, model); nil != err {
+		logging.LogErrorf("execute auth page failed: %s", err)
+		c.Status(500)
+		return
+	}
+	data = buf.Bytes()
 	c.Data(http.StatusOK, "text/html; charset=utf-8", data)
 	c.Data(http.StatusOK, "text/html; charset=utf-8", data)
 }
 }