|
@@ -0,0 +1,42 @@
|
|
|
+// import { App } from 'vue'
|
|
|
+import { createI18n } from 'vue-i18n'
|
|
|
+import { useLocaleStoreWithOut } from '@/store/modules/locale'
|
|
|
+// import { I18n, I18nOptions } from 'vue-i18n'
|
|
|
+// import { setHtmlPageLang } from './helper'
|
|
|
+
|
|
|
+export let i18n
|
|
|
+
|
|
|
+const createI18nOptions = async () => {
|
|
|
+ const localeStore = useLocaleStoreWithOut()
|
|
|
+ const locale = localeStore.getCurrentLocale
|
|
|
+ const localeMap = localeStore.getLocaleMap
|
|
|
+ const defaultLocal = await import(`../../locales/${locale.lang}.js`)
|
|
|
+ const message = defaultLocal.default ?? {}
|
|
|
+
|
|
|
+ document.querySelector('html')?.setAttribute('lang', locale.lang)
|
|
|
+
|
|
|
+ localeStore.setCurrentLocale({
|
|
|
+ lang: locale.lang
|
|
|
+ // elLocale: elLocal
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ legacy: false,
|
|
|
+ locale: locale.lang,
|
|
|
+ fallbackLocale: locale.lang,
|
|
|
+ messages: {
|
|
|
+ [locale.lang]: message
|
|
|
+ },
|
|
|
+ availableLocales: localeMap.map((v) => v.lang),
|
|
|
+ sync: true,
|
|
|
+ silentTranslationWarn: true,
|
|
|
+ missingWarn: false,
|
|
|
+ silentFallbackWarn: true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const setupI18n = async (app) => {
|
|
|
+ const options = await createI18nOptions()
|
|
|
+ i18n = createI18n(options)
|
|
|
+ app.use(i18n)
|
|
|
+}
|