fix: 优化plugin-locale

This commit is contained in:
万纯 2021-03-05 18:04:10 +08:00
parent b32f087e12
commit 1673ef4b7e
2 changed files with 10 additions and 10 deletions

View File

@ -52,21 +52,21 @@ const i18n = createI18n({
});
window.localStorage.setItem("fes_locale", i18n.global.locale);
const setLocale = ({ lang }) => {
const setLocale = ({ locale }) => {
if (isRef(i18n.global.locale)) {
i18n.global.locale.value = lang;
i18n.global.locale.value = locale;
} else {
i18n.global.locale = lang;
i18n.global.locale = locale;
}
window.localStorage.setItem("fes_locale", lang);
window.localStorage.setItem("fes_locale", locale);
};
const addLocale = ({ lang, messages }) => {
messages[lang] = messages;
const addLocale = ({ locale, messages }) => {
messages[locale] = messages;
if (isRef(i18n.global.messages)) {
i18n.global.messages.value[lang] = messages;
i18n.global.messages.value[locale] = messages;
} else {
i18n.global.messages[lang] = messages;
i18n.global.messages[locale] = messages;
}
};

View File

@ -78,8 +78,8 @@ export default {
onMounted(() => {
console.log(router);
setTimeout(() => {
locale.setLocale({ lang: 'en-US' });
locale.addLocale({ lang: 'ja-JP', messages: { test: 'テスト' } });
locale.setLocale({ locale: 'en-US' });
locale.addLocale({ locale: 'ja-JP', messages: { test: 'テスト' } });
console.log(locale.getAllLocales());
}, 2000);
setTimeout(() => {