Support dynamic locale for element plus (#237)
This commit is contained in:
1 parent
3577558970
commit
5d4da94cdd
5 files changed
+85
-33
No files matched your search
+61
-15
@@ -1,8 +1,10 @@
|
||||
<template>
|
||||
<el-config-provider :locale="locale">
|
||||
<el-config-provider :locale="epLocale">
|
||||
<auth-panel v-if="authPopup" />
|
||||
<router-view />
|
||||
<el-tag v-if="isTest" size="large" class="tag" type="warning">{{ $t('index.button.testEnv') }}</el-tag>
|
||||
<el-tag v-if="isTest" size="large" class="fixed bottom-4 right-4 z-50" type="warning">
|
||||
{{ $t('index.button.testEnv') }}
|
||||
</el-tag>
|
||||
</el-config-provider>
|
||||
</template>
|
||||
|
||||
@@ -10,24 +12,57 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElConfigProvider, ElTag } from 'element-plus';
|
||||
import AuthPanel from './components/common/AuthPanel.vue';
|
||||
import locale from 'element-plus/es/locale/lang/en';
|
||||
import { isTest } from '@/constants/endpoint';
|
||||
import { getLocale } from './i18n';
|
||||
|
||||
const elementPlusLocaleMap: Record<string, () => Promise<any>> = {
|
||||
en: () => import('element-plus/es/locale/lang/en'),
|
||||
de: () => import('element-plus/es/locale/lang/de'),
|
||||
pt: () => import('element-plus/es/locale/lang/pt'),
|
||||
es: () => import('element-plus/es/locale/lang/es'),
|
||||
fr: () => import('element-plus/es/locale/lang/fr'),
|
||||
'zh-CN': () => import('element-plus/es/locale/lang/zh-cn'),
|
||||
'zh-TW': () => import('element-plus/es/locale/lang/zh-tw'),
|
||||
it: () => import('element-plus/es/locale/lang/it'),
|
||||
ko: () => import('element-plus/es/locale/lang/ko'),
|
||||
ja: () => import('element-plus/es/locale/lang/ja'),
|
||||
ru: () => import('element-plus/es/locale/lang/ru'),
|
||||
pl: () => import('element-plus/es/locale/lang/pl'),
|
||||
fi: () => import('element-plus/es/locale/lang/fi'),
|
||||
sv: () => import('element-plus/es/locale/lang/sv'),
|
||||
el: () => import('element-plus/es/locale/lang/el'),
|
||||
uk: () => import('element-plus/es/locale/lang/uk'),
|
||||
ar: () => import('element-plus/es/locale/lang/ar'),
|
||||
sr: () => import('element-plus/es/locale/lang/sr')
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
name: 'App',
|
||||
components: {
|
||||
ElConfigProvider,
|
||||
AuthPanel,
|
||||
ElTag
|
||||
ElTag,
|
||||
AuthPanel
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isTest,
|
||||
locale
|
||||
epLocale: null as any
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
authPopup() {
|
||||
return this.$store.state.auth.flow === 'popup' && this.$store.state.auth.visible;
|
||||
},
|
||||
currentLocale(): string {
|
||||
return getLocale(this.$i18n.locale as string);
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
currentLocale: {
|
||||
immediate: true,
|
||||
handler() {
|
||||
this.loadElementPlusLocale();
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -37,15 +72,26 @@ export default defineComponent({
|
||||
this.$store.dispatch('logout');
|
||||
this.$store.dispatch('login');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadElementPlusLocale() {
|
||||
const localeCode = this.currentLocale;
|
||||
console.debug(`[i18n] Loading Element Plus locale for: ${localeCode}`);
|
||||
|
||||
const loader = elementPlusLocaleMap[localeCode];
|
||||
if (!loader) {
|
||||
console.warn(`[i18n] No Element Plus locale found for: ${localeCode}`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const module = await loader();
|
||||
this.epLocale = module.default;
|
||||
console.debug(`[i18n] Loaded Element Plus locale: ${localeCode}`);
|
||||
} catch (err) {
|
||||
console.error(`[i18n] Failed to load Element Plus locale for: ${localeCode}`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.tag {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
z-index: 10000;
|
||||
}
|
||||
</style>
|
||||
@@ -22,9 +22,7 @@ export default defineComponent({
|
||||
required: false,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
data() {},
|
||||
watch: {}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
<template>
|
||||
<el-dialog :model-value="visible" @close="onClose">
|
||||
<div class="flex settings">
|
||||
<aside class="w-40 h-full border-r">
|
||||
<div class="flex settings h-[460px]">
|
||||
<aside class="h-full border-r">
|
||||
<el-menu class="border-r-0">
|
||||
<el-menu-item
|
||||
v-for="(item, index) in navItems"
|
||||
:key="index"
|
||||
:index="item.key"
|
||||
:class="['flex items-center px-2 cursor-pointer py-2', activeTab === item.key ? 'active' : '']"
|
||||
:class="[
|
||||
'flex w-[160px] truncate items-center px-2 cursor-pointer py-2',
|
||||
activeTab === item.key ? 'active' : ''
|
||||
]"
|
||||
@click="activeTab = item.key"
|
||||
>
|
||||
<font-awesome-icon :icon="item.icon" class="mr-2" />
|
||||
@@ -70,17 +73,19 @@ export default defineComponent({
|
||||
data() {
|
||||
return {
|
||||
activeTab: 'general',
|
||||
showSuggestions: true,
|
||||
navItems: [
|
||||
showSuggestions: true
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
navItems() {
|
||||
return [
|
||||
{ key: 'general', label: this.$t('common.settings.general'), icon: faCog },
|
||||
{ key: 'site', label: this.$t('common.settings.site'), icon: faBell },
|
||||
{ key: 'seo', label: this.$t('common.settings.seo'), icon: faUserShield },
|
||||
{ key: 'distribution', label: this.$t('common.settings.distribution'), icon: faMoneyBill },
|
||||
{ key: 'function', label: this.$t('common.settings.function'), icon: faMagic }
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
];
|
||||
},
|
||||
currentTabTitle() {
|
||||
const current = this.navItems.find((item) => item.key === this.activeTab);
|
||||
return current ? current.label : '';
|
||||
@@ -96,9 +101,3 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.settings {
|
||||
height: 460px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user