feat: 合并代码

This commit is contained in:
duanshuwen
2025-12-21 20:25:38 +08:00
parent 11702dc9d2
commit 7d6b07e092
56 changed files with 2533 additions and 379 deletions

44
src/renderer/i18n.ts Normal file
View File

@@ -0,0 +1,44 @@
import { createI18n, I18n, type I18nOptions } from 'vue-i18n';
const languages = ['zh', 'en'] as const;
type LanguageType = (typeof languages)[number];
async function createI18nInstance() {
const options: I18nOptions = {
legacy: false,
locale: 'zh',
fallbackLocale: 'zh',
messages: {
zh: await import('@locales/zh.json').then(m => m.default),
en: await import('@locales/en.json').then(m => m.default),
}
}
const i18n = createI18n(options);
return i18n
}
export const i18n = await createI18nInstance();
export async function setLanguage(lang:LanguageType,_i18n?:I18n){
const __i18n = _i18n ?? i18n;
if(__i18n.mode === 'legacy'){
__i18n.global.locale = lang;
return;
}
(__i18n.global.locale as unknown as Ref<LanguageType>).value = lang;
}
export function getLanguage(){
if(i18n.mode === 'legacy'){
return i18n.global.locale;
}
return (i18n.global.locale as unknown as Ref<LanguageType>).value;
}
export default i18n;