mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-18 04:27:36 +08:00
🚧 WIP: add i18n ing
This commit is contained in:
27
src/universal/i18n/index.ts
Normal file
27
src/universal/i18n/index.ts
Normal 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 }
|
||||
12
src/universal/i18n/zh-CN.ts
Normal file
12
src/universal/i18n/zh-CN.ts
Normal 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
|
||||
2
src/universal/types/types.d.ts
vendored
2
src/universal/types/types.d.ts
vendored
@@ -335,3 +335,5 @@ interface IMiniWindowPos {
|
||||
}
|
||||
|
||||
type PromiseResType<T> = T extends Promise<infer R> ? R : T
|
||||
|
||||
type ILocalesKey = import('#/i18n/zh-CN').ILocalesKey
|
||||
|
||||
Reference in New Issue
Block a user