2020-11-23 00:35:15 +08:00
|
|
|
|
import { App, unref } from 'vue';
|
|
|
|
|
|
import type { I18n, I18nOptions } from 'vue-i18n';
|
2020-11-19 23:01:27 +08:00
|
|
|
|
|
|
|
|
|
|
import { createI18n } from 'vue-i18n';
|
|
|
|
|
|
import localeMessages from '/@/locales';
|
|
|
|
|
|
import { useLocale } from '/@/hooks/web/useLocale';
|
2020-11-23 00:35:15 +08:00
|
|
|
|
import { useLocaleSetting } from '/@/settings/use/useLocaleSetting';
|
2020-11-19 23:01:27 +08:00
|
|
|
|
|
2020-11-23 00:35:15 +08:00
|
|
|
|
const { setupLocale } = useLocale();
|
2020-11-19 23:01:27 +08:00
|
|
|
|
|
2020-11-23 00:35:15 +08:00
|
|
|
|
const { getLang, getAvailableLocales, getFallbackLocale } = useLocaleSetting();
|
2020-11-19 23:01:27 +08:00
|
|
|
|
const localeData: I18nOptions = {
|
|
|
|
|
|
legacy: false,
|
2020-11-23 00:35:15 +08:00
|
|
|
|
locale: unref(getLang),
|
|
|
|
|
|
fallbackLocale: unref(getFallbackLocale),
|
2020-11-19 23:01:27 +08:00
|
|
|
|
messages: localeMessages,
|
2020-11-23 00:35:15 +08:00
|
|
|
|
availableLocales: unref(getAvailableLocales),
|
2020-11-19 23:01:27 +08:00
|
|
|
|
sync: true, //If you don’t want to inherit locale from global scope, you need to set sync of i18n component option to false.
|
|
|
|
|
|
silentTranslationWarn: false, // true - warning off
|
|
|
|
|
|
silentFallbackWarn: true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let i18n: I18n;
|
|
|
|
|
|
|
|
|
|
|
|
// setup i18n instance with glob
|
|
|
|
|
|
export function setupI18n(app: App) {
|
|
|
|
|
|
i18n = createI18n(localeData) as I18n;
|
2020-11-23 00:35:15 +08:00
|
|
|
|
setupLocale();
|
2020-11-19 23:01:27 +08:00
|
|
|
|
app.use(i18n);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-23 00:35:15 +08:00
|
|
|
|
export function getI18n(): I18n {
|
|
|
|
|
|
return i18n;
|
2020-11-19 23:01:27 +08:00
|
|
|
|
}
|