Fix pagination component internationalization issue (#17886)

- Add proper Element Plus internationalization configuration merging
- Implement custom pagination translations for both English and Chinese
- Update locale store to merge DataEase's custom translations with Element Plus standard structure
- Fix the issue where pagination component shows '共xx页' in English mode
This commit is contained in:
taojinlong
2026-01-31 23:59:53 +08:00
committed by taojinlong
parent 49e625fedd
commit d4c41a673c
4 changed files with 108 additions and 10 deletions

View File

@@ -4838,3 +4838,24 @@ export default {
batch_del_confirm: 'Are you sure you want to delete {0} Webhooks?'
}
}
// Element Plus internationalization configuration
element_plus: {
el: {
pagination: {
goto: 'Go to',
pagesize: '/page',
total: 'Total {total}',
pageClassifier: '',
page: 'Page',
prev: 'Go to previous page',
next: 'Go to next page',
currentPage: 'page {pager}',
prevPages: 'Previous {pager} pages',
nextPages: 'Next {pager} pages',
deprecationWarning: 'Deprecated usages detected, please refer to the el-pagination documentation for more details',
}
}
}
}

View File

@@ -4692,5 +4692,23 @@ export default {
content_type: '内容类型',
del_confirm: '确定删除该 Webhook吗',
batch_del_confirm: '确定删除 {0} 个 Webhook吗'
},
// Element Plus internationalization configuration
element_plus: {
el: {
pagination: {
goto: "前往",
pagesize: "/",
total: " {total} ",
pageClassifier: "",
page: "",
prev: "上一页",
next: "下一页",
currentPage: " {pager} ",
prevPages: "向前 {pager} ",
nextPages: "向后 {pager} ",
deprecationWarning: "检测到已弃用的用法请参阅 el-pagination 文档以了解更多详情"
}
}
}
}

View File

@@ -1,4 +1,5 @@
import type { App } from 'vue'
import { locale } from 'element-plus-secondary'
// 需要全局引入一些组件如ElScrollbar不然一些下拉项样式有问题
import { ElLoading, ElScrollbar } from 'element-plus-secondary'
@@ -25,3 +26,8 @@ export const setupElementPlusIcons = (app: App<Element>) => {
app.component(key, component)
}
}
// 导出Element Plus国际化配置函数
export const setElementPlusLocale = (localeObj: any) => {
locale(localeObj)
}

View File

@@ -1,15 +1,50 @@
import { defineStore } from 'pinia'
import { store } from '../index'
import type { LocaleDropdownType } from 'types/localeDropdown'
import zhCn from 'element-plus-secondary/es/locale/lang/zh-cn'
import en from 'element-plus-secondary/es/locale/lang/en'
import tw from 'element-plus-secondary/es/locale/lang/zh-tw'
import zhCnOriginal from 'element-plus-secondary/es/locale/lang/zh-cn'
import enOriginal from 'element-plus-secondary/es/locale/lang/en'
import twOriginal from 'element-plus-secondary/es/locale/lang/zh-tw'
import { getLocale } from '@/utils/utils'
import request from '@/config/axios'
import { setElementPlusLocale } from '@/plugins/element-plus'
// 合并DataEase的国际化配置到Element Plus的国际化结构中
const mergeLocaleData = (baseLocale: any, customData: any) => {
const merged = JSON.parse(JSON.stringify(baseLocale || {}))
const mergeRecursive = (obj: any, source: any) => {
for (const key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key])) {
if (!obj[key]) obj[key] = {}
mergeRecursive(obj[key], source[key])
} else {
obj[key] = source[key]
}
}
}
return obj
}
return mergeRecursive(merged, customData)
}
// 加载DataEase的国际化配置
const loadCustomLocaleData = async (lang: string) => {
try {
const localeModule = await import(`../../locales/${lang}.ts`)
const localeData = localeModule.default || localeModule
return localeData.element_plus || {}
} catch (error) {
console.warn(`Failed to load custom locale data for ${lang}:`, error)
return {}
}
}
const elLocaleMap = {
'zh-CN': zhCn,
en: en,
tw: tw
'zh-CN': zhCnOriginal,
en: enOriginal,
tw: twOriginal
}
interface LocaleState {
customLoaded: boolean
@@ -82,15 +117,33 @@ export const useLocaleStore = defineStore('locales', {
}
},
actions: {
setCurrentLocale(localeMap: LocaleDropdownType) {
async setCurrentLocale(localeMap: LocaleDropdownType) {
// this.locale = Object.assign(this.locale, localeMap)
this.currentLocale.lang = localeMap?.lang
this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
const baseLocale = elLocaleMap[localeMap?.lang]
const customData = await loadCustomLocaleData(localeMap?.lang)
// 合并基础国际化配置和自定义配置
this.currentLocale.elLocale = mergeLocaleData(baseLocale, customData)
// 同时更新Element Plus的国际化配置
if (this.currentLocale.elLocale) {
setElementPlusLocale(this.currentLocale.elLocale)
}
// wsCache.set('lang', localeMap?.lang)
},
setLang(language: string) {
async setLang(language: string) {
this.currentLocale.lang = language
this.currentLocale.elLocale = elLocaleMap[language]
const baseLocale = elLocaleMap[language]
const customData = await loadCustomLocaleData(language)
// 合并基础国际化配置和自定义配置
this.currentLocale.elLocale = mergeLocaleData(baseLocale, customData)
// 同时更新Element Plus的国际化配置
if (this.currentLocale.elLocale) {
setElementPlusLocale(this.currentLocale.elLocale)
}
}
}
})