You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
1 year ago
|
import { createI18n } from 'vue-i18n';
|
||
|
import { Language } from 'element-plus/es/locale/index';
|
||
|
import ElZhCn from 'element-plus/es/locale/lang/zh-cn';
|
||
|
import ElEn from 'element-plus/es/locale/lang/en';
|
||
|
import { getCookieLocale } from '@/utils/common';
|
||
|
import en from './locales/en';
|
||
|
import zhCn from './locales/zh-cn';
|
||
|
|
||
|
const messages = {
|
||
|
'zh-cn': {
|
||
|
...zhCn,
|
||
|
},
|
||
|
en: {
|
||
|
...en,
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const elMessages: Record<string, Language> = {
|
||
|
'zh-cn': ElZhCn,
|
||
|
en: ElEn,
|
||
|
};
|
||
|
|
||
|
export const languages: Record<string, string> = { 'zh-cn': '中文', en: 'English' };
|
||
|
|
||
|
const i18nFallbackLocale = import.meta.env.VITE_I18N_FALLBACK_LOCALE || 'zh-cn';
|
||
|
|
||
|
export function getElementPlusLocale(lang: string): Language {
|
||
|
return elMessages[lang] ?? elMessages[i18nFallbackLocale] ?? ElZhCn;
|
||
|
}
|
||
|
|
||
|
export function getLanguage(): string {
|
||
|
const chooseLanguage = getCookieLocale();
|
||
|
if (chooseLanguage) return chooseLanguage;
|
||
|
return import.meta.env.VITE_I18N_LOCALE || 'zh-cn';
|
||
|
}
|
||
|
|
||
|
export default createI18n({
|
||
|
legacy: false,
|
||
|
locale: getLanguage(),
|
||
|
fallbackLocale: i18nFallbackLocale,
|
||
|
globalInjection: true,
|
||
|
messages,
|
||
|
});
|