mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-18 03:17:29 +08:00
2cc03cb080
add Traditional Chinese translations for all application strings include new language files for artist, history, donation, favorite, login, search, user, common, download, player, settings, comp components update main i18n configuration to include zh-Hant language add zh-Hant option to language switcher component
41 lines
886 B
TypeScript
41 lines
886 B
TypeScript
import enUS from './lang/en-US';
|
|
import zhCN from './lang/zh-CN';
|
|
import zhHant from './lang/zh-Hant';
|
|
|
|
const messages = {
|
|
'zh-CN': zhCN,
|
|
'en-US': enUS,
|
|
'zh-Hant': zhHant
|
|
} as const;
|
|
|
|
type Language = keyof typeof messages;
|
|
|
|
// 为主进程提供一个简单的 i18n 实现
|
|
const mainI18n = {
|
|
global: {
|
|
currentLocale: 'zh-CN' as Language,
|
|
get locale() {
|
|
return this.currentLocale;
|
|
},
|
|
set locale(value: Language) {
|
|
this.currentLocale = value;
|
|
},
|
|
t(key: string) {
|
|
const keys = key.split('.');
|
|
let current: any = messages[this.currentLocale];
|
|
for (const k of keys) {
|
|
if (current[k] === undefined) {
|
|
// 如果找不到翻译,返回键名
|
|
return key;
|
|
}
|
|
current = current[k];
|
|
}
|
|
return current;
|
|
},
|
|
messages
|
|
}
|
|
};
|
|
|
|
export type { Language };
|
|
export default mainI18n;
|