feat(i18n): 实现应用语言本地存储功能
This commit is contained in:
@@ -7,10 +7,12 @@ import messages from '@intlify/unplugin-vue-i18n/messages';
|
|||||||
import { createI18n } from 'vue-i18n';
|
import { createI18n } from 'vue-i18n';
|
||||||
|
|
||||||
export function install({ app }: { app: import('vue').App<Element> }) {
|
export function install({ app }: { app: import('vue').App<Element> }) {
|
||||||
|
const locale = useLocalStorage<string>('app-locale', navigator.language);
|
||||||
|
|
||||||
// https://vue-i18n.intlify.dev/guide/essentials/started.html#registering-the-i18n-plugin
|
// https://vue-i18n.intlify.dev/guide/essentials/started.html#registering-the-i18n-plugin
|
||||||
const i18n = createI18n({
|
const i18n = createI18n({
|
||||||
legacy: false, // you must set `false`, to use Composition API
|
legacy: false, // you must set `false`, to use Composition API
|
||||||
locale: navigator.language,
|
locale: locale.value,
|
||||||
fallbackRoot: false,
|
fallbackRoot: false,
|
||||||
// flatJson: true,
|
// flatJson: true,
|
||||||
missing: (locale, key /* , instance, type */) => {
|
missing: (locale, key /* , instance, type */) => {
|
||||||
@@ -21,5 +23,8 @@ export function install({ app }: { app: import('vue').App<Element> }) {
|
|||||||
fallbackWarn: !true,
|
fallbackWarn: !true,
|
||||||
messages,
|
messages,
|
||||||
});
|
});
|
||||||
|
watchEffect(() => {
|
||||||
|
locale.value = i18n.global.locale.value;
|
||||||
|
});
|
||||||
app.use(i18n);
|
app.use(i18n);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user