Commit b695e195 authored by guxukai's avatar guxukai

chore: 国际化planA实现

parent f1f8a6eb
// 按钮配置
export default {
baas: {
button: {
login: {
zh: '登录',
en: 'login',
},
},
},
}
export default {
baas: {
menu: {
lookup: {
zh: '开发参考',
en: 'lookup',
......@@ -61,6 +59,4 @@ export default {
zh: '接口文档',
en: 'app openapi',
},
},
},
}
......@@ -8,6 +8,7 @@ import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
import { camelCase, isPlainObject, upperFirst } from 'lodash'
import path from 'path'
import { modules } from '@/pages/account/views/cropped/home/components'
import { getFilename } from '@shared/utils/filename.utils'
/**
* 返回拆分的国际化配置
......@@ -35,10 +36,15 @@ function func(
Object.entries(v).map(([key, value]) => func(value, [...parentKeys, key], config))
return config
}
const requireModules = require.context('./config', false, /config\.ts$/iu)
// e.g. $t('baas.button.login')
const requireModules = require.context('./config', false, /\.ts$/iu)
const localesList = requireModules.keys().map(filePath => {
const component = requireModules(filePath)
return component.default
return {
baas: {
[getFilename(filePath)]: component.default,
},
}
})
export const i18n = createI18n({
locale: sessionStorage.getItem('layout')
......
// 获取文件名(不含后缀)
export function getFilename(params: string) {
return params.replace(/(.*\/)*([^.]+).*/gi, '$2')
}
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