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
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "add i18n for element ",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "cqc@cuiqingcai.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
<meta http-equiv="Pragma" content="no-cache" />
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
<meta http-equiv="Expires" content="0" />
|
<meta http-equiv="Expires" content="0" />
|
||||||
<title>Ace Data Cloud</title>
|
<title>Ace Data Cloud</title>
|
||||||
|
<link rel="icon" href="/src/images/favicon.ico" />
|
||||||
|
<link rel="stylesheet" href="/src/assets/css/loading.css" />
|
||||||
<script>
|
<script>
|
||||||
var _hmt = _hmt || [];
|
var _hmt = _hmt || [];
|
||||||
(function () {
|
(function () {
|
||||||
|
|||||||
+61
-15
@@ -1,8 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-config-provider :locale="locale">
|
<el-config-provider :locale="epLocale">
|
||||||
<auth-panel v-if="authPopup" />
|
<auth-panel v-if="authPopup" />
|
||||||
<router-view />
|
<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>
|
</el-config-provider>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -10,24 +12,57 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElConfigProvider, ElTag } from 'element-plus';
|
import { ElConfigProvider, ElTag } from 'element-plus';
|
||||||
import AuthPanel from './components/common/AuthPanel.vue';
|
import AuthPanel from './components/common/AuthPanel.vue';
|
||||||
import locale from 'element-plus/es/locale/lang/en';
|
|
||||||
import { isTest } from '@/constants/endpoint';
|
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({
|
export default defineComponent({
|
||||||
|
name: 'App',
|
||||||
components: {
|
components: {
|
||||||
ElConfigProvider,
|
ElConfigProvider,
|
||||||
AuthPanel,
|
ElTag,
|
||||||
ElTag
|
AuthPanel
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isTest,
|
isTest,
|
||||||
locale
|
epLocale: null as any
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
authPopup() {
|
authPopup() {
|
||||||
return this.$store.state.auth.flow === 'popup' && this.$store.state.auth.visible;
|
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() {
|
mounted() {
|
||||||
@@ -37,15 +72,26 @@ export default defineComponent({
|
|||||||
this.$store.dispatch('logout');
|
this.$store.dispatch('logout');
|
||||||
this.$store.dispatch('login');
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.tag {
|
|
||||||
position: fixed;
|
|
||||||
bottom: 10px;
|
|
||||||
right: 10px;
|
|
||||||
z-index: 10000;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -22,9 +22,7 @@ export default defineComponent({
|
|||||||
required: false,
|
required: false,
|
||||||
default: ''
|
default: ''
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
data() {},
|
|
||||||
watch: {}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog :model-value="visible" @close="onClose">
|
<el-dialog :model-value="visible" @close="onClose">
|
||||||
<div class="flex settings">
|
<div class="flex settings h-[460px]">
|
||||||
<aside class="w-40 h-full border-r">
|
<aside class="h-full border-r">
|
||||||
<el-menu class="border-r-0">
|
<el-menu class="border-r-0">
|
||||||
<el-menu-item
|
<el-menu-item
|
||||||
v-for="(item, index) in navItems"
|
v-for="(item, index) in navItems"
|
||||||
:key="index"
|
:key="index"
|
||||||
:index="item.key"
|
: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"
|
@click="activeTab = item.key"
|
||||||
>
|
>
|
||||||
<font-awesome-icon :icon="item.icon" class="mr-2" />
|
<font-awesome-icon :icon="item.icon" class="mr-2" />
|
||||||
@@ -70,17 +73,19 @@ export default defineComponent({
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
activeTab: 'general',
|
activeTab: 'general',
|
||||||
showSuggestions: true,
|
showSuggestions: true
|
||||||
navItems: [
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
navItems() {
|
||||||
|
return [
|
||||||
{ key: 'general', label: this.$t('common.settings.general'), icon: faCog },
|
{ key: 'general', label: this.$t('common.settings.general'), icon: faCog },
|
||||||
{ key: 'site', label: this.$t('common.settings.site'), icon: faBell },
|
{ key: 'site', label: this.$t('common.settings.site'), icon: faBell },
|
||||||
{ key: 'seo', label: this.$t('common.settings.seo'), icon: faUserShield },
|
{ key: 'seo', label: this.$t('common.settings.seo'), icon: faUserShield },
|
||||||
{ key: 'distribution', label: this.$t('common.settings.distribution'), icon: faMoneyBill },
|
{ key: 'distribution', label: this.$t('common.settings.distribution'), icon: faMoneyBill },
|
||||||
{ key: 'function', label: this.$t('common.settings.function'), icon: faMagic }
|
{ key: 'function', label: this.$t('common.settings.function'), icon: faMagic }
|
||||||
]
|
];
|
||||||
};
|
},
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
currentTabTitle() {
|
currentTabTitle() {
|
||||||
const current = this.navItems.find((item) => item.key === this.activeTab);
|
const current = this.navItems.find((item) => item.key === this.activeTab);
|
||||||
return current ? current.label : '';
|
return current ? current.label : '';
|
||||||
@@ -96,9 +101,3 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.settings {
|
|
||||||
height: 460px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Reference in new issue
Block a user