ow
This commit is contained in:
1 parent
1404640f16
commit
2bbf016cbf
167 files changed
+18941
-589
No files matched your search
@@ -0,0 +1,28 @@
|
||||
//npm i lodash-es
|
||||
//npm i --save-dev @types/lodash-es
|
||||
import { set } from 'lodash-es';
|
||||
|
||||
|
||||
export function genMessage(langs: Record<string, Record<string, any>>, prefix = 'lang') {
|
||||
const obj: Recordable = {};
|
||||
|
||||
Object.keys(langs).forEach((key) => {
|
||||
const langFileModule = langs[key].default;
|
||||
let fileName = key.replace(`./${prefix}/`, '').replace(/^\.\//, '');
|
||||
const lastIndex = fileName.lastIndexOf('.');
|
||||
fileName = fileName.substring(0, lastIndex);
|
||||
const keyList = fileName.split('/');
|
||||
const moduleName = keyList.shift();
|
||||
const objKey = keyList.join('.');
|
||||
|
||||
if (moduleName) {
|
||||
if (objKey) {
|
||||
set(obj, moduleName, obj[moduleName] || {});
|
||||
set(obj[moduleName], objKey, langFileModule);
|
||||
} else {
|
||||
set(obj, moduleName, langFileModule || {});
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import type { I18nOptions } from 'vue-i18n';
|
||||
import type { App } from 'vue';
|
||||
|
||||
//这儿使用await,需要如下两步处理
|
||||
//npm install vite-plugin-top-level-await -D
|
||||
//配置vite.config.ts(topLevelAwait)
|
||||
//引入的不同语言文件
|
||||
const options = await createI18nOptions();
|
||||
|
||||
//这个类型可以自己配置,毕竟每个人做的都不一样
|
||||
const i18n:any =createI18n( options)
|
||||
|
||||
async function createI18nOptions(): Promise<I18nOptions> {
|
||||
const locale:string='zh-cn';
|
||||
const en = await import(`./lang/en.ts`);
|
||||
const cn = await import(`./lang/zh-cn.ts`);
|
||||
|
||||
return {
|
||||
legacy: false,
|
||||
globalInjection: true, //全局生效$t
|
||||
locale: locale, // 默认cn翻译
|
||||
messages: {
|
||||
['zh-cn']: cn.default?.message,
|
||||
['en']: en.default?.message,
|
||||
},
|
||||
sync: true, //If you don’t want to inherit locale from global scope, you need to set sync of i18n component option to false.
|
||||
silentTranslationWarn: true, // true - warning off
|
||||
missingWarn: false,
|
||||
silentFallbackWarn: true,
|
||||
};
|
||||
}
|
||||
|
||||
// setup i18n instance with global
|
||||
export async function setupI18n(app: App) {
|
||||
app.use(i18n);
|
||||
}
|
||||
|
||||
|
||||
export default i18n;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { genMessage } from '../helper';
|
||||
import antdLocale from 'ant-design-vue/es/locale/en_US';
|
||||
|
||||
const modules = import.meta.glob('./en/*.json', { eager: true });
|
||||
export default {
|
||||
message: {
|
||||
...genMessage(modules as Recordable<Recordable>, 'en'),
|
||||
antdLocale,
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"header": {
|
||||
"createdtime": "Login Time:",
|
||||
"dashboard": "Welcome",
|
||||
"logout": "Exit System",
|
||||
"message": "New Message(0)",
|
||||
"amentPassword": "Ament Password",
|
||||
"amentUserLocalName": "Ament Username"
|
||||
},
|
||||
"notification": {
|
||||
"message": "System prompt",
|
||||
"description": "System has exited"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"register": {
|
||||
"twoDifferentPasswords": "Two different passwords",
|
||||
"pleaseEnterYourConfirmationPassword": "Please enter your confirmation password"
|
||||
},
|
||||
"changePassword": {
|
||||
"changePassword": "Change Password",
|
||||
"oldPassword":"Old Password",
|
||||
"newPassword":"New Password",
|
||||
"confirmPassword":"Confirm Password",
|
||||
"pleaseInputOldPassword":"Please input old password",
|
||||
"pleaseInputNewPassword":"Please input new password"
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"notification":{
|
||||
"identityAuthenticationFailure":"Identity authentication failure.",
|
||||
"theServerHasStoppedWorking":"The server has stopped working.",
|
||||
"unauthorizedAccess":"Unauthorized access",
|
||||
"errorMessage":"Error",
|
||||
"warnMessage":"Warn"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { genMessage } from '../helper';
|
||||
import antdLocale from 'ant-design-vue/es/locale/zh_CN';
|
||||
|
||||
const modules = import.meta.glob('./zh-cn/*.json', { eager: true });
|
||||
|
||||
export default {
|
||||
message: {
|
||||
...genMessage(modules as Recordable<Recordable>, 'zh-cn'),
|
||||
antdLocale,
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"header": {
|
||||
"amentUserLocalName": "修改用户名称",
|
||||
"amentPassword": "修改密码",
|
||||
"createdtime": "登录时间:",
|
||||
"dashboard": "欢迎页",
|
||||
"logout": "退出系统",
|
||||
"message": "新消息(0)"
|
||||
},
|
||||
"layout": {
|
||||
"header": {
|
||||
"dashboard": ""
|
||||
}
|
||||
},
|
||||
"notification": {
|
||||
"description": "用户已登出",
|
||||
"message": "系统提示:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"register": {
|
||||
"pleaseEnterYourConfirmationPassword": "请输入确认密码",
|
||||
"twoDifferentPasswords": "两次密码不一样"
|
||||
},
|
||||
"changePassword": {
|
||||
"changePassword": "修改密码",
|
||||
"oldPassword":"旧密码",
|
||||
"newPassword":"新密码",
|
||||
"confirmPassword":"确认密码",
|
||||
"pleaseInputOldPassword":"请输入旧密码",
|
||||
"pleaseInputNewPassword":"请输入新密码"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"notification": {
|
||||
"errorMessage": "错误提示",
|
||||
"identityAuthenticationFailure": "身份认证失败,请重新登录.",
|
||||
"theServerHasStoppedWorking": "服务器器已停止工作,请联系管理员.",
|
||||
"unauthorizedAccess": "未授权访问,请联系管理员.",
|
||||
"warnMessage": "系统提示"
|
||||
},
|
||||
"request": {
|
||||
"notification": {
|
||||
"identityAuthenticationFailure": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user