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.
52 lines
1.0 KiB
52 lines
1.0 KiB
import Vue from 'vue'
|
|
import VueI18n from 'vue-i18n'
|
|
|
|
import { getLanguage } from '@/utils/cookies'
|
|
|
|
// element-ui built-in lang
|
|
import elementEnLocale from 'element-ui/lib/locale/lang/en'
|
|
import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'
|
|
|
|
// User defined lang
|
|
import enLocale from './en'
|
|
import zhLocale from './zh'
|
|
|
|
Vue.use(VueI18n)
|
|
|
|
const messages = {
|
|
en: {
|
|
...enLocale,
|
|
...elementEnLocale
|
|
},
|
|
'zh-Hans': {
|
|
...zhLocale,
|
|
...elementZhLocale
|
|
}
|
|
}
|
|
|
|
export const getLocale = () => {
|
|
const cookieLanguage = getLanguage()
|
|
if (cookieLanguage) {
|
|
return cookieLanguage
|
|
}
|
|
const language = navigator.language.toLowerCase()
|
|
const locales = Object.keys(messages)
|
|
for (const locale of locales) {
|
|
if (language.indexOf(locale) > -1) {
|
|
return locale
|
|
}
|
|
}
|
|
return 'zh-Hans'
|
|
}
|
|
|
|
const i18n = new VueI18n({
|
|
locale: getLocale(),
|
|
messages
|
|
})
|
|
|
|
export function setLanguage(language: string, values: any) {
|
|
i18n.mergeLocaleMessage(language, values)
|
|
i18n.locale = language
|
|
}
|
|
|
|
export default i18n
|
|
|