Skip to content

Commit 88416db

Browse files
committed
feat(i18n): add support for internationalization
1 parent c4df297 commit 88416db

File tree

12 files changed

+513
-96
lines changed

12 files changed

+513
-96
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ index.php
66
output
77
conf.yaml
88
dist
9-
*.log
9+
*.log
10+
translate.*.toml

active.en-US.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
About = "About"
2+
AboutContent = "# Introduce \n\n Fetch Github Hosts is a Github Hosts synchronization tool primarily designed to address \n\n issues such as slow access to Github or other issues for researchers and learners\n---\n# License\nGNU General Public License v3.0\n\n# Version"
3+
CheckUpdate = "Update Check"
4+
CheckUpdateFail = "Check for updates failed"
5+
CleanGithubHostsFail = "Clearing github records in hosts failed"
6+
CleanGithubHostsSuccess = "The github record in the hosts file has been successfully cleared"
7+
ClearHosts = "Clear hosts"
8+
ClientFetchHostsGetErrorLog = "Failed to obtain the latest hosts"
9+
ClientFetchHostsReadErrorLog = "Failed to read the latest hosts"
10+
ClientMode = "Client Mode"
11+
CurrentIsNewest = "Currently, it is the latest version"
12+
DownloadNow = "Download Now"
13+
Feedback = "Feedback"
14+
FetchGithubHostsFail = "Failed to obtain the Host for Github"
15+
GetHostRecordErr = "Failed to obtain host records"
16+
GetIntervalMinutes = "Get interval (minutes)"
17+
GetIntervalNeedInt = "Get interval must be an integer"
18+
HostsOptCustom = "Custom hosts source"
19+
HostsOptOfficial = "Official designated hosts source"
20+
HostsOrigin = "Hosts origin"
21+
ListeningAddress = "Listening address {{.Addr}}"
22+
ListeningAddressWait = "Listening address: To be started"
23+
LogCreatedFail = "Log file creation failed"
24+
NetworkRequestFail = "Network request error"
25+
Ok = "OK"
26+
OpenHome = "Open home"
27+
ParseDomainsJsonErr = "domain.json parsing failed"
28+
ParseUpdateResponseFail = "Failed to parse and update response content"
29+
PortMustBeInt = "Port number must be an integer"
30+
ReadDomainsJsonErr = "Error reading file domains.json"
31+
ReadHostsErr = "Error reading file hosts"
32+
ReadIndexFileErr = "Failed to read homepage template file"
33+
ReadUpdateResponseFail = "Failed to read update response content"
34+
RemoteHostsFetchErrorLog = "Failed to update Github Hosts: {{.E}}"
35+
RemoteHostsFetchStopLog = "Stop obtaining hosts"
36+
RemoteHostsFetchSuccessLog = "Successfully updated Github Hosts!"
37+
RemoteHostsUrl = "Remote hosts url"
38+
RemoteHostsUrlLog = "Remote hosts obtaining links: {{.Url}}"
39+
RequestFail = "request failure"
40+
ServerFetchHostsErrorLog = "Failed to execute update Github Hosts: {{.E}}"
41+
ServerFetchHostsStopErrorLog = "Failed to close port listening"
42+
ServerFetchHostsStopLog = "Stopping updating hosts service"
43+
ServerFetchHostsStopSuccessLog = "Stopped updating hosts service"
44+
ServerFetchHostsSuccessLog = "Successfully executed update Github Hosts!"
45+
ServerFetchIndexFileErr = "Failed to retrieve homepage file: {{.E}}"
46+
ServerMode = "Server Mode"
47+
ServerStartErrorLog = "Service startup failed (possibly due to the target port being occupied): {{.E}}"
48+
ServerStartSuccessHostsJsonLinkLog = "JSON format link for hosts: http://127.0.0.1:{{.Port}}/hosts.json"
49+
ServerStartSuccessHostsLinkLog = "Hosts file link: http://127.0.0.1:{{.Port}}/hosts.txt"
50+
ServerStartSuccessLog = "Successfully listened to HTTP service:http://127.0.0.1:{{.Port}}"
51+
Start = "Start"
52+
StartupAutoGet = "Startup auto start"
53+
StartupAutoGetTips = "The automatic acquisition status of the startup software has changed and will take effect the next time the program is launched!"
54+
StartupPort = "Start port"
55+
Stop = "Stop"
56+
Tip = "Tip"
57+
UpdateLater = "Update later"
58+
UpdateTip = "Update Tip"
59+
UpdateTipContent = "Detected a new version, do you need to download the latest version immediately?"
60+
VersionParseFail = "Version number parsing failed"
61+
WriteHostsJsonFileErr = "Writing data to the hosts.json file failed"
62+
WriteHostsNoPermission = "Writing hosts file failed, please start this program as a super administrator!"
63+
WriteHostsTxtFileErr = "Writing data to the hosts.txt file failed"
64+
WriteIndexFileErr = "Failed to write update information to the homepage file"

active.zh-CN.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
About = "关于"
2+
AboutContent = "# 介绍\nFetch Github Hosts是主要为解决研究及学习人员访问Github过慢或其他问题而提供的Github Hosts同步工具\n---\n# 开源协议\nGNU General Public License v3.0\n\n# 版本号"
3+
CheckUpdate = "检查更新"
4+
CheckUpdateFail = "检查更新失败"
5+
CleanGithubHostsFail = "清除hosts中的github记录失败"
6+
CleanGithubHostsSuccess = "hosts文件中的github记录已经清除成功"
7+
ClearHosts = "清除hosts"
8+
ClientFetchHostsGetErrorLog = "获取最新的hosts失败"
9+
ClientFetchHostsReadErrorLog = "读取最新的hosts失败"
10+
ClientMode = "客户端模式"
11+
CurrentIsNewest = "当前已是最新版本"
12+
DownloadNow = "立即下载"
13+
Feedback = "反馈建议"
14+
FetchGithubHostsFail = "获取Github的Host失败"
15+
GetHostRecordErr = "获取主机记录失败"
16+
GetIntervalMinutes = "获取间隔(分钟)"
17+
GetIntervalNeedInt = "获取间隔必须为整数"
18+
HostsOptCustom = "自定义hosts源"
19+
HostsOptOfficial = "官方指定hosts源"
20+
HostsOrigin = "Hosts源"
21+
ListeningAddress = "监听地址 {{.Addr}}"
22+
ListeningAddressWait = "监听地址:待启动"
23+
LogCreatedFail = "日志文件创建失败"
24+
NetworkRequestFail = "网络请求错误"
25+
Ok = "确认"
26+
OpenHome = "打开主界面"
27+
ParseDomainsJsonErr = "domain.json解析失败"
28+
ParseUpdateResponseFail = "解析更新响应内容失败"
29+
PortMustBeInt = "端口号必须为整数"
30+
ReadDomainsJsonErr = "读取文件domains.json错误"
31+
ReadHostsErr = "读取文件hosts错误"
32+
ReadIndexFileErr = "读取首页模板文件失败"
33+
ReadUpdateResponseFail = "读取更新响应内容失败"
34+
RemoteHostsFetchErrorLog = "更新Github-Hosts失败: {{.E}}"
35+
RemoteHostsFetchStopLog = "停止获取hosts"
36+
RemoteHostsFetchSuccessLog = "更新Github-Hosts成功!"
37+
RemoteHostsUrl = "远程Hosts链接"
38+
RemoteHostsUrlLog = "远程hosts获取链接: {{.Url}}"
39+
RequestFail = "请求失败"
40+
ServerFetchHostsErrorLog = "执行更新Github-Hosts失败:{{.E}}"
41+
ServerFetchHostsStopErrorLog = "关闭端口监听失败"
42+
ServerFetchHostsStopLog = "正在停止更新hosts服务"
43+
ServerFetchHostsStopSuccessLog = "已停止更新hosts服务"
44+
ServerFetchHostsSuccessLog = "执行更新Github-Hosts成功!"
45+
ServerFetchIndexFileErr = "获取首页文件失败:{{.E}}"
46+
ServerMode = "服务端模式"
47+
ServerStartErrorLog = "服务启动失败(可能是目标端口已被占用):{{.E}}"
48+
ServerStartSuccessHostsJsonLinkLog = "hosts的JSON格式链接:http://127.0.0.1:{{.Port}}/hosts.json"
49+
ServerStartSuccessHostsLinkLog = "hosts文件链接:http://127.0.0.1:{{.Port}}/hosts.txt"
50+
ServerStartSuccessLog = "已监听HTTP服务成功:http://127.0.0.1:{{.Port}}"
51+
Start = "启动"
52+
StartupAutoGet = "启动软件自动获取"
53+
StartupAutoGetTips = "启动软件自动获取状态已改变,将会在下次启动程序时生效!"
54+
StartupPort = "启动端口号"
55+
Stop = "停止"
56+
Tip = "提示"
57+
UpdateLater = "稍后更新"
58+
UpdateTip = "更新提示"
59+
UpdateTipContent = "检测到有新的版本,是否立即需要去下载最新版本?"
60+
VersionParseFail = "版本号解析失败"
61+
WriteHostsJsonFileErr = "写入数据到hosts.json文件失败"
62+
WriteHostsNoPermission = "写入hosts文件失败,请用超级管理员身份启动本程序!"
63+
WriteHostsTxtFileErr = "写入数据到hosts.txt文件失败"
64+
WriteIndexFileErr = "写入更新信息到首页文件失败"

args.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type CmdArgs struct {
1515
Escalate bool `long:"escalate" description:"提权执行"`
1616
DontEscalate bool `long:"de" description:"禁止提权执行"`
1717
Version bool `short:"v" long:"version" description:"查看当前版本"`
18+
Lang string `long:"lang" short:"l" description:"使用语言"`
1819
}
1920

2021
func ParseBootArgs() *CmdArgs {

conf.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
)
66

77
type FetchConf struct {
8+
Lang string
89
Client struct {
910
Interval int
1011
Method string
@@ -19,6 +20,7 @@ type FetchConf struct {
1920
}
2021

2122
func (f *FetchConf) Storage() {
23+
viper.Set("lang", f.Lang)
2224
viper.Set("client.interval", f.Client.Interval)
2325
viper.Set("client.method", f.Client.Method)
2426
viper.Set("client.selectorigin", f.Client.SelectOrigin)
@@ -35,6 +37,7 @@ func LoadFetchConf() *FetchConf {
3537
viper.AddConfigPath(AppExecDir())
3638
viper.SetConfigName("conf")
3739
viper.SetConfigType("yaml")
40+
viper.SetDefault("lang", "zh-CN")
3841
viper.SetDefault("client.interval", 60)
3942
viper.SetDefault("client.method", "官方指定hosts源")
4043
viper.SetDefault("client.selectorigin", "FetchGithubHosts")

0 commit comments

Comments
 (0)