feat: i18n获取浏览器默认语言

This commit is contained in:
“huailei000” 2022-04-01 15:41:34 +08:00 committed by 老广
parent ec2674a956
commit 07036cdea7

View File

@ -7,11 +7,12 @@ import date from './date'
import VueCookie from 'vue-cookie' import VueCookie from 'vue-cookie'
Vue.use(VueI18n) Vue.use(VueI18n)
const cookieLang = VueCookie.get('django_language')
const cookieLang = VueCookie.get('django_language') || 'en' const browserLang = navigator.systemLanguage || navigator.language
const defaultLang = cookieLang.slice(0, 2) let lang = cookieLang || browserLang || 'zh'
lang = lang.slice(0, 2)
const i18n = new VueI18n({ const i18n = new VueI18n({
locale: defaultLang, locale: lang,
fallbackLocale: 'en', fallbackLocale: 'en',
silentFallbackWarn: true, silentFallbackWarn: true,
silentTranslationWarn: true, silentTranslationWarn: true,