You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
847 B
TypeScript

3 years ago
// 自定义国际化配置
import { createI18n } from 'vue-i18n';
// 本地语言包
import enUSLocale from './en_US';
import zhCNLocale from './zh_CN';
3 years ago
import Cookies from 'js-cookie';
3 years ago
const messages = {
zh_CN: {
...zhCNLocale
},
en_US: {
...enUSLocale
}
3 years ago
};
/**
* 使
* @returns zh-cn|en ...
*/
export const getLanguage = () => {
// 本地缓存获取
3 years ago
let language = Cookies.get('language');
if (language) {
return language;
}
// 浏览器使用语言
language = navigator.language.toLowerCase();
const locales = Object.keys(messages);
for (const locale of locales) {
if (language.indexOf(locale) > -1) {
return locale;
}
}
return 'zh_CN';
3 years ago
};
const i18n = createI18n({
legacy: false,
locale: getLanguage(),
3 years ago
messages
3 years ago
});
export default i18n;