Skip to content

Commit

Permalink
make translations in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Feb 20, 2022
1 parent 584cbd7 commit f097acb
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
app.ini
dist
*.exe
*.po~
18 changes: 0 additions & 18 deletions frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
3 changes: 2 additions & 1 deletion frontend/src/lib/translate/gettext.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
30 changes: 13 additions & 17 deletions frontend/src/locale/en/LC_MESSAGES/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 ""

Expand Down Expand Up @@ -134,7 +130,7 @@ msgstr ""
msgid "Edit Site"
msgstr ""

#: src/views/other/Install.vue:30
#: src/views/other/Install.vue:31
msgid "Email (*)"
msgstr ""

Expand Down Expand Up @@ -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 ""

Expand All @@ -228,7 +224,7 @@ msgstr ""
msgid "Login"
msgstr ""

#: src/views/other/Login.vue:28
#: src/views/other/Login.vue:30
msgid "Login successful"
msgstr ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""
41 changes: 20 additions & 21 deletions frontend/src/locale/zh_CN/LC_MESSAGES/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "创建时间"
Expand All @@ -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)"

Expand Down Expand Up @@ -136,7 +132,7 @@ msgstr "编辑配置文件"
msgid "Edit Site"
msgstr "编辑站点"

#: src/views/other/Install.vue:30
#: src/views/other/Install.vue:31
msgid "Email (*)"
msgstr "邮箱 (*)"

Expand Down Expand Up @@ -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 "无效的邮箱!"

Expand All @@ -230,7 +226,7 @@ msgstr "系统负载:"
msgid "Login"
msgstr "登录"

#: src/views/other/Login.vue:28
#: src/views/other/Login.vue:30
msgid "Login successful"
msgstr "登录成功"

Expand All @@ -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"
Expand Down Expand Up @@ -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 "请输入您的用户名!"

Expand Down Expand Up @@ -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 "服务器错误"

Expand Down Expand Up @@ -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}"

Expand All @@ -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."
Expand All @@ -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"
30 changes: 13 additions & 17 deletions frontend/src/locale/zh_TW/LC_MESSAGES/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 ""

Expand Down Expand Up @@ -133,7 +129,7 @@ msgstr ""
msgid "Edit Site"
msgstr ""

#: src/views/other/Install.vue:30
#: src/views/other/Install.vue:31
msgid "Email (*)"
msgstr ""

Expand Down Expand Up @@ -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 ""

Expand All @@ -227,7 +223,7 @@ msgstr ""
msgid "Login"
msgstr ""

#: src/views/other/Login.vue:28
#: src/views/other/Login.vue:30
msgid "Login successful"
msgstr ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""
Loading

0 comments on commit f097acb

Please sign in to comment.