feat(i18n): 实现应用语言本地存储功能
All checks were successful
CI/CD Pipeline / playwright (push) Successful in 3m46s
CI/CD Pipeline / build-and-deploy (push) Successful in 4m6s

This commit is contained in:
严浩
2025-10-28 09:55:20 +08:00
parent 50911ada4e
commit 88ca601d07

View File

@@ -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);
} }