-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathi18n.ts
44 lines (37 loc) · 1.36 KB
/
i18n.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const store = {
"en": {
"recoveryCodes": "Recovery Codes",
"nodata": "No Data",
"noRecoveryCodes": "Recovery codes have not been saved to github-2fa yet, please save the data in a timely manner to avoid forgetting.",
"recoveryCodesLessTip": "Recovery codes only {param0} left, please generate it promptly.",
"startTip": "Start managing your Github 2FA Code.",
"goToGen": "Go to generate",
"noSectet": "Secret has not been generated yet.",
},
"cn": {
"recoveryCodes": "重置码",
"nodata": "暂无数据",
"noRecoveryCodes": "尚未保存 Recovery codes 至 github-2fa, 及时保存数据,避免遗忘。",
"recoveryCodesLessTip": "重置码仅余 {param0} 个,请及时生成。",
"startTip": "开始管理你的 Github 2FA Code。",
"goToGen": "前往生成",
"noSectet": "尚未生成 secret,",
}
}
const lang = navigator.language.toLowerCase()
const cn = lang.includes('zh') || lang.includes('cn')
const type = cn ? 'cn': 'en'
const i18n = (key: keyof typeof store["cn"], ...params) => {
const text = store[type][key]
if (!text) return ""
if (params.length > 0) {
return text.replace(/\{([^}]+)\}/g, (...args) => {
const match = /param(\d+)/.exec(args[1]);
if (!match) return params[0]
const index = match[1]
return params[index]
});
}
return text;
}
export default i18n