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.

35 lines
927 B
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//i18n-setup.js
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import axios from '@/utils/request';
import cn from '@/i18n/lang/cn';
import en from '@/i18n/lang/en';
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: 'en', // 设置语言环境
fallbackLocale: 'en',
messages: { cn, en }, // 设置语言环境信息
});
// 由于微信小程序的运行机制问题需声明如下一行H5和APP非必填
Vue.prototype._i18n = i18n;
Vue.filter('t', (v: any) => i18n.t(v));
Vue.filter('tc', (v: any) => i18n.tc(v));
Vue.filter('te', (v: any) => i18n.te(v));
Vue.filter('d', (v: any) => i18n.d(v));
Vue.filter('n', (v: any) => i18n.n(v));
export type Lang = 'cn' | 'en';
export function setI18nLanguage(lang: string) {
i18n.locale = lang;
axios.defaults.headers.common['Accept-Language'] = lang;
document.querySelector('html')?.setAttribute('lang', lang);
return lang;
}
export default i18n;