feat: 新增主进程功能
This commit is contained in:
44
src/renderer/i18n.ts
Normal file
44
src/renderer/i18n.ts
Normal 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;
|
||||
@@ -4,6 +4,7 @@ import router from "./router";
|
||||
import App from "./App.vue";
|
||||
import ElementPlus from 'element-plus'
|
||||
import locale from 'element-plus/es/locale/lang/zh-cn'
|
||||
import i18n from './i18n'
|
||||
// import './permission'
|
||||
|
||||
// 样式文件隔离
|
||||
@@ -30,6 +31,7 @@ app.use(createPinia());
|
||||
app.use(router);
|
||||
app.use(ElementPlus, { locale })
|
||||
app.use(components)
|
||||
app.use(i18n)
|
||||
|
||||
// 挂载应用到 DOM
|
||||
app.mount("#app");
|
||||
|
||||
Reference in New Issue
Block a user