-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.js
32 lines (26 loc) · 999 Bytes
/
i18n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { nextTick } from 'vue'
import { createI18n } from 'vue-i18n'
import config, { Property } from '@/config'
let i18n
let currentLocale
export const getLocale = () => currentLocale
export const setI18nLanguage = (locale) => {
// eslint-disable-next-line no-param-reassign
if (i18n.mode === 'legacy') i18n.global.locale = locale
// eslint-disable-next-line no-param-reassign
else i18n.global.locale.value = locale
currentLocale = locale
document.querySelector('html').setAttribute('lang', locale)
}
export async function loadLocale(locale) {
const messages = await import(`@/locale/${locale}.json`)
i18n.global.setLocaleMessage(locale, messages.default)
return nextTick()
}
export default function setupI18n(options = { locale: config.properties[Property.DEFAULT_LOCALE] }) {
return new Promise((resolve) => {
i18n = createI18n({ ...options, fallbackLocale: config.properties[Property.FALLBACK_LOCALE] })
setI18nLanguage(options.locale)
resolve(i18n)
})
}