Commit b31fd5c7 authored by guxukai's avatar guxukai

chore: 国际化planA实现

parent d0e1fab4
// 按钮配置
export const buttonConfig = {
zh: {
baas: {},
},
en: {
baas: {},
},
}
type ButtonConfigItem = {
export default {
baas: {
button: {}
}
button: {
login: {
zh: '登录',
en: 'login',
},
},
},
}
// 导航菜单配置
export const menusConfig: {
zh: MenusConfigItem
en: MenusConfigItem
} = {
zh: {
baas: {
menu: {
lookup: '开发参考',
icons: '图标库',
i18n: '国际化',
home: '首页',
chain: '链管理',
'announce-list': '公告列表',
notice: '站内信',
'alliance-chain': '联盟链',
'parallel-chain': '平行链',
'chain-log': '链日志',
'address-management': '地址管理',
'key-management': '密钥管理',
openapi: 'OpenApi',
'app-management': '授权管理',
'app-openapi': '接口文档',
export default {
baas: {
menu: {
lookup: {
zh: '开发参考',
en: 'lookup',
},
},
},
en: {
baas: {
menu: {
lookup: 'lookup',
icons: 'icons',
i18n: 'i18n',
home: 'home',
chain: 'chain',
'announce-list': 'announce list',
notice: 'notice',
'alliance-chain': 'alliance chain',
'parallel-chain': 'parallel chain',
'chain-log': 'chain log',
'address-management': 'address management',
'key-management': 'key management',
openapi: 'openapi',
'app-management': 'app management',
'app-openapi': 'app openapi',
icons: {
zh: '图标库',
en: 'icons',
},
i18n: {
zh: '国际化',
en: 'i18n',
},
home: {
zh: '首页',
en: 'home',
},
chain: {
zh: '链管理',
en: 'chain',
},
'announce-list': {
zh: '公告列表',
en: 'announce list',
},
notice: {
zh: '站内信',
en: 'notice',
},
'alliance-chain': {
zh: '联盟链',
en: 'alliance chain',
},
'parallel-chain': {
zh: '平行链',
en: 'parallel chain',
},
'chain-log': {
zh: '链日志',
en: 'chain log',
},
'address-management': {
zh: '地址管理',
en: 'address management',
},
'key-management': {
zh: '密钥管理',
en: 'key management',
},
openapi: {
zh: 'OpenApi',
en: 'OpenApi',
},
'app-management': {
zh: '授权管理',
en: 'app management',
},
'app-openapi': {
zh: '接口文档',
en: 'app openapi',
},
},
},
}
type MenusConfigItem = {
baas: {
menu: {
lookup: string
icons: string
i18n: string
home: string
notice: string
'announce-list': string
chain: string
'alliance-chain': string
'parallel-chain': string
'chain-log': string
'address-management': string
'key-management': string
openapi: string
'app-management': string
'app-openapi': string
}
}
}
......@@ -3,9 +3,43 @@ import { createI18n } from 'vue-i18n'
// element-plus国际化
import enLocale from 'element-plus/lib/locale/lang/en'
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
import { menusConfig } from '@shared/plugins/i18n/config/menu-config'
import { buttonConfig } from '@shared/plugins/i18n/config/button-config'
const localesList = [menusConfig, buttonConfig]
// import { menuConfig } from '@shared/plugins/i18n/config/menu-config'
// import { buttonConfig } from '@shared/plugins/i18n/config/button-config'
import { camelCase, isPlainObject, upperFirst } from 'lodash'
import path from 'path'
import { modules } from '@/pages/account/views/cropped/home/components'
/**
* 返回拆分的国际化配置
* @param v
* @param parentKeys
* @param config
*/
function func(
v,
parentKeys: string[] = [],
config = {
zh: {},
en: {},
},
) {
if (!isPlainObject(v)) {
if (parentKeys[parentKeys.length - 1] === 'zh') {
config.zh[parentKeys.slice(0, parentKeys.length - 1).join('.')] = v
}
if (parentKeys[parentKeys.length - 1] === 'en') {
config.en[parentKeys.slice(0, parentKeys.length - 1).join('.')] = v
}
return config
}
Object.entries(v).map(([key, value]) => func(value, [...parentKeys, key], config))
return config
}
const requireModules = require.context('./config', false, /config\.ts$/iu)
const localesList = requireModules.keys().map(filePath => {
const component = requireModules(filePath)
return component.default
})
export const i18n = createI18n({
locale: sessionStorage.getItem('layout')
? JSON.parse(sessionStorage.getItem('layout') as string).currentLocale
......@@ -13,11 +47,11 @@ export const i18n = createI18n({
fallbackLocale: 'zh', // set fallback locale
messages: {
zh: {
baas: Object.assign({}, ...localesList.map(v => v.zh.baas)),
...Object.assign({}, ...localesList.map(v => func(v).zh)),
...zhLocale,
},
en: {
baas: Object.assign({}, ...localesList.map(v => v.en.baas)),
...Object.assign({}, ...localesList.map(v => func(v).en)),
...enLocale,
},
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment