make translations in frontend

This commit is contained in:
0xJacky 2022-02-21 00:32:56 +08:00
parent 584cbd745c
commit f097acb3e9
12 changed files with 53 additions and 95 deletions

View file

@ -2,25 +2,7 @@ package frontend
import (
"embed"
"github.com/0xJacky/pofile"
"log"
"path"
)
//go:embed dist
var DistFS embed.FS
var Translations pofile.Dict
func InitTranslations() {
lang := []string{"zh_CN", "zh_TW", "en"}
Translations = make(pofile.Dict)
for _, v := range lang {
p, err := pofile.Parse(path.Join("frontend", "src", "locale", v, "LC_MESSAGES", "app.po"))
if err != nil {
log.Fatalln(err)
}
Translations[p.Header.Language] = make(pofile.Dict)
Translations[p.Header.Language] = p.ToDict()
}
}

View file

@ -1,6 +1,7 @@
import {translate} from 'vue-gettext'
import store from '@/lib/store'
import {availableLanguages} from '@/lib/translate/index'
import translations from '@/translations.json'
let lang = window.navigator.language.replace('-', '_')
if(availableLanguages[lang] === undefined) {
@ -23,6 +24,6 @@ export const {
gettext: $gettext, gettextInterpolate: $interpolate
} = translate
translate.initTranslations(store.state.settings.translations, config)
translate.initTranslations(translations, config)
export default $gettext

View file

@ -77,10 +77,6 @@ msgstr ""
msgid "Configurations"
msgstr ""
#: src/views/dashboard/DashBoard.vue:52
msgid "CPU"
msgstr ""
#: src/views/user/User.vue:23
msgid "Created at"
msgstr ""
@ -89,7 +85,7 @@ msgstr ""
msgid "Dashboard"
msgstr ""
#: src/views/other/Install.vue:104
#: src/views/other/Install.vue:105
msgid "Database (Optional, default: database)"
msgstr ""
@ -134,7 +130,7 @@ msgstr ""
msgid "Edit Site"
msgstr ""
#: src/views/other/Install.vue:30
#: src/views/other/Install.vue:31
msgid "Email (*)"
msgstr ""
@ -207,7 +203,7 @@ msgstr ""
msgid "Intermediate Certification Authorities: %{issuer}"
msgstr ""
#: src/views/other/Install.vue:45
#: src/views/other/Install.vue:46
msgid "Invalid E-mail!"
msgstr ""
@ -228,7 +224,7 @@ msgstr ""
msgid "Login"
msgstr ""
#: src/views/other/Login.vue:28
#: src/views/other/Login.vue:30
msgid "Login successful"
msgstr ""
@ -281,23 +277,23 @@ msgstr ""
msgid "OK"
msgstr ""
#: src/views/other/Login.vue:55 src/views/user/User.vue:13
#: src/views/other/Login.vue:56 src/views/user/User.vue:13
msgid "Password"
msgstr ""
#: src/views/other/Install.vue:82
#: src/views/other/Install.vue:83
msgid "Password (*)"
msgstr ""
#: src/views/other/Install.vue:49
#: src/views/other/Install.vue:50
msgid "Please input your E-mail!"
msgstr ""
#: src/views/other/Install.vue:95 src/views/other/Login.vue:68
#: src/views/other/Install.vue:96 src/views/other/Login.vue:69
msgid "Please input your password!"
msgstr ""
#: src/views/other/Install.vue:72 src/views/other/Login.vue:45
#: src/views/other/Install.vue:73 src/views/other/Login.vue:46
msgid "Please input your username!"
msgstr ""
@ -329,7 +325,7 @@ msgid "Saved successfully"
msgstr ""
#: src/views/config/ConfigEdit.vue:35 src/views/domain/DomainEdit.vue:71
#: src/views/other/Login.vue:33
#: src/views/other/Login.vue:35
msgid "Server error"
msgstr ""
@ -369,7 +365,7 @@ msgid ""
"from Let's Encrypt\" first."
msgstr ""
#: src/views/other/Install.vue:119
#: src/views/other/Install.vue:120
msgid "The filename cannot contain the following characters: %{c}"
msgstr ""
@ -401,10 +397,10 @@ msgstr ""
msgid "Used: %{used} / Total: %{total}"
msgstr ""
#: src/views/other/Login.vue:32 src/views/user/User.vue:5
#: src/views/other/Login.vue:33 src/views/user/User.vue:5
msgid "Username"
msgstr ""
#: src/views/other/Install.vue:59
#: src/views/other/Install.vue:60
msgid "Username (*)"
msgstr ""

View file

@ -79,10 +79,6 @@ msgstr "配置名称"
msgid "Configurations"
msgstr "配置"
#: src/views/dashboard/DashBoard.vue:52
msgid "CPU"
msgstr "CPU"
#: src/views/user/User.vue:23
msgid "Created at"
msgstr "创建时间"
@ -91,7 +87,7 @@ msgstr "创建时间"
msgid "Dashboard"
msgstr "仪表盘"
#: src/views/other/Install.vue:104
#: src/views/other/Install.vue:105
msgid "Database (Optional, default: database)"
msgstr "数据库 (可选,默认: database)"
@ -136,7 +132,7 @@ msgstr "编辑配置文件"
msgid "Edit Site"
msgstr "编辑站点"
#: src/views/other/Install.vue:30
#: src/views/other/Install.vue:31
msgid "Email (*)"
msgstr "邮箱 (*)"
@ -209,7 +205,7 @@ msgstr "安装"
msgid "Intermediate Certification Authorities: %{issuer}"
msgstr "中级证书颁发机构: %{issuer}"
#: src/views/other/Install.vue:45
#: src/views/other/Install.vue:46
msgid "Invalid E-mail!"
msgstr "无效的邮箱!"
@ -230,7 +226,7 @@ msgstr "系统负载:"
msgid "Login"
msgstr "登录"
#: src/views/other/Login.vue:28
#: src/views/other/Login.vue:30
msgid "Login successful"
msgstr "登录成功"
@ -244,8 +240,8 @@ msgid ""
"directory to <code>HTTPChallengePort</code> (default: 9180) before getting "
"the certificate."
msgstr ""
"在获取签发证书前,请确保配置文件中已将 <code>.well-known</code> 目录反向代"
"到<code>HTTPChallengePort</code> (默认: 9180)"
"在获取签发证书前,请确保配置文件中已将 <code>.well-known</code> 目录反向代"
"到<code>HTTPChallengePort</code> (默认: 9180)"
#: src/router/index.js:60
msgid "Manage Configs"
@ -285,23 +281,23 @@ msgstr "注意:当前配置中的 server_name 必须为需要申请证书的
msgid "OK"
msgstr "确定"
#: src/views/other/Login.vue:55 src/views/user/User.vue:13
#: src/views/other/Login.vue:56 src/views/user/User.vue:13
msgid "Password"
msgstr "密码"
#: src/views/other/Install.vue:82
#: src/views/other/Install.vue:83
msgid "Password (*)"
msgstr "密码 (*)"
#: src/views/other/Install.vue:49
#: src/views/other/Install.vue:50
msgid "Please input your E-mail!"
msgstr "请输入您的邮箱!"
#: src/views/other/Install.vue:95 src/views/other/Login.vue:68
#: src/views/other/Install.vue:96 src/views/other/Login.vue:69
msgid "Please input your password!"
msgstr "请输入您的密码!"
#: src/views/other/Install.vue:72 src/views/other/Login.vue:45
#: src/views/other/Install.vue:73 src/views/other/Login.vue:46
msgid "Please input your username!"
msgstr "请输入您的用户名!"
@ -333,7 +329,7 @@ msgid "Saved successfully"
msgstr "保存成功"
#: src/views/config/ConfigEdit.vue:35 src/views/domain/DomainEdit.vue:71
#: src/views/other/Login.vue:33
#: src/views/other/Login.vue:35
msgid "Server error"
msgstr "服务器错误"
@ -375,7 +371,7 @@ msgstr ""
"系统将会每小时检测一次该域名证书若距离上次签发已超过1个月则将自动续签。"
"<br/>如果您之前没有证书,请先点击 \"从 Let's Encrypt 获取证书\"。"
#: src/views/other/Install.vue:119
#: src/views/other/Install.vue:120
msgid "The filename cannot contain the following characters: %{c}"
msgstr "文件名不能包含以下字符: %{c}"
@ -385,8 +381,8 @@ msgid ""
"fields in your configuration file. The configuration filename cannot be "
"changed after it has been created."
msgstr ""
"只有在您的配置文件中有相应字段时,下列的配置才能生效。配置文件名称创建后不"
"修改。"
"只有在您的配置文件中有相应字段时,下列的配置才能生效。配置文件名称创建后不"
"修改。"
#: src/views/domain/DomainEdit.vue:134
msgid "This operation will lose the custom configuration."
@ -409,10 +405,13 @@ msgstr "已使用: %{u}, 缓存: %{c}, 空闲: %{f}, 物理内存: %{p}"
msgid "Used: %{used} / Total: %{total}"
msgstr "已使用: %{used} / 总共: %{total}"
#: src/views/other/Login.vue:32 src/views/user/User.vue:5
#: src/views/other/Login.vue:33 src/views/user/User.vue:5
msgid "Username"
msgstr "用户名"
#: src/views/other/Install.vue:59
#: src/views/other/Install.vue:60
msgid "Username (*)"
msgstr "用户名 (*)"
#~ msgid "CPU"
#~ msgstr "CPU"

View file

@ -76,10 +76,6 @@ msgstr ""
msgid "Configurations"
msgstr ""
#: src/views/dashboard/DashBoard.vue:52
msgid "CPU"
msgstr ""
#: src/views/user/User.vue:23
msgid "Created at"
msgstr ""
@ -88,7 +84,7 @@ msgstr ""
msgid "Dashboard"
msgstr ""
#: src/views/other/Install.vue:104
#: src/views/other/Install.vue:105
msgid "Database (Optional, default: database)"
msgstr ""
@ -133,7 +129,7 @@ msgstr ""
msgid "Edit Site"
msgstr ""
#: src/views/other/Install.vue:30
#: src/views/other/Install.vue:31
msgid "Email (*)"
msgstr ""
@ -206,7 +202,7 @@ msgstr ""
msgid "Intermediate Certification Authorities: %{issuer}"
msgstr ""
#: src/views/other/Install.vue:45
#: src/views/other/Install.vue:46
msgid "Invalid E-mail!"
msgstr ""
@ -227,7 +223,7 @@ msgstr ""
msgid "Login"
msgstr ""
#: src/views/other/Login.vue:28
#: src/views/other/Login.vue:30
msgid "Login successful"
msgstr ""
@ -280,23 +276,23 @@ msgstr ""
msgid "OK"
msgstr ""
#: src/views/other/Login.vue:55 src/views/user/User.vue:13
#: src/views/other/Login.vue:56 src/views/user/User.vue:13
msgid "Password"
msgstr ""
#: src/views/other/Install.vue:82
#: src/views/other/Install.vue:83
msgid "Password (*)"
msgstr ""
#: src/views/other/Install.vue:49
#: src/views/other/Install.vue:50
msgid "Please input your E-mail!"
msgstr ""
#: src/views/other/Install.vue:95 src/views/other/Login.vue:68
#: src/views/other/Install.vue:96 src/views/other/Login.vue:69
msgid "Please input your password!"
msgstr ""
#: src/views/other/Install.vue:72 src/views/other/Login.vue:45
#: src/views/other/Install.vue:73 src/views/other/Login.vue:46
msgid "Please input your username!"
msgstr ""
@ -328,7 +324,7 @@ msgid "Saved successfully"
msgstr ""
#: src/views/config/ConfigEdit.vue:35 src/views/domain/DomainEdit.vue:71
#: src/views/other/Login.vue:33
#: src/views/other/Login.vue:35
msgid "Server error"
msgstr ""
@ -368,7 +364,7 @@ msgid ""
"from Let's Encrypt\" first."
msgstr ""
#: src/views/other/Install.vue:119
#: src/views/other/Install.vue:120
msgid "The filename cannot contain the following characters: %{c}"
msgstr ""
@ -400,10 +396,10 @@ msgstr ""
msgid "Used: %{used} / Total: %{total}"
msgstr ""
#: src/views/other/Login.vue:32 src/views/user/User.vue:5
#: src/views/other/Login.vue:33 src/views/user/User.vue:5
msgid "Username"
msgstr ""
#: src/views/other/Install.vue:59
#: src/views/other/Install.vue:60
msgid "Username (*)"
msgstr ""

View file

@ -11,7 +11,7 @@ import utils from '@/lib/utils'
import api from '@/api'
import GetTextPlugin from 'vue-gettext'
import {availableLanguages} from '@/lib/translate'
import http from '@/lib/http'
import translations from '@/translations.json'
Vue.use(utils)
@ -23,14 +23,10 @@ Vue.prototype.$api = api
Vue.use(GetTextPlugin, {
availableLanguages,
defaultLanguage: store.getters.current_language,
translations: store.state.settings.translations,
translations: translations,
silent: true
})
http.get('/translations.json').then(r => {
if(r) store.commit('update_translations', r)
})
NProgress.configure({
easing: 'ease',
speed: 500,

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
{"version":"1.1.0","build_id":22,"total_build":39}
{"version":"1.1.0","build_id":23,"total_build":40}