🚧 WIP: add i18n ing

This commit is contained in:
PiEgg
2022-01-10 10:20:56 +08:00
parent 04701d4202
commit c2991dde2f
8 changed files with 120 additions and 51 deletions

View File

@@ -0,0 +1,27 @@
import { ZH_CN } from './zh-CN'
import { ObjectAdapter, I18n } from '@picgo/i18n'
const languageList = {
'zh-CN': ZH_CN
}
const lowercaseKeys = (obj: any) =>
Object.keys(obj).reduce((acc: any, key: string) => {
acc[key.toLowerCase()] = obj[key]
return acc
}, {})
// FIXME: @picgo/i18n no lowecase
const objectAdapter = new ObjectAdapter(lowercaseKeys(languageList))
const i18n = new I18n({
adapter: objectAdapter,
defaultLanguage: 'zh-cn'
})
// FIXME: @picgo/i18n args should be optional
const T = (key: ILocalesKey, args: IStringKeyMap = {}): string => {
return i18n.translate(key, args)!
}
export { i18n, T }

View File

@@ -0,0 +1,12 @@
export const ZH_CN = {
ABOUT: '关于',
OPEN_MAIN_WINDOW: '打开主窗口',
CHOOSE_DEFAULT_PICBED: '选择默认图床',
OPEN_UPDATE_HELPER: '打开更新助手',
PRIVACY_AGREEMENT: '隐私协议',
RELOAD_APP: '重启应用',
UPLOAD_SUCCESSFULLY: '上传成功',
QUIT: '退出'
}
export type ILocalesKey = keyof typeof ZH_CN

View File

@@ -335,3 +335,5 @@ interface IMiniWindowPos {
}
type PromiseResType<T> = T extends Promise<infer R> ? R : T
type ILocalesKey = import('#/i18n/zh-CN').ILocalesKey