From 1740d3d2818b3d8404de33b69dfda6e9b4473a12 Mon Sep 17 00:00:00 2001 From: QuangNN Date: Mon, 30 Oct 2023 23:48:25 +0700 Subject: [PATCH] add vue i18n --- web/i18n/index.js | 1 + web/i18n/messages/cn.json | 30 +++++++++++++++++++ web/i18n/messages/en.json | 30 +++++++++++++++++++ web/src/router/routes/index.js | 17 ++++++----- web/src/views/profile/index.vue | 51 +++++++++++++++++---------------- 5 files changed, 97 insertions(+), 32 deletions(-) diff --git a/web/i18n/index.js b/web/i18n/index.js index 1fcb146..aa3fdf5 100644 --- a/web/i18n/index.js +++ b/web/i18n/index.js @@ -5,6 +5,7 @@ import messages from './messages' const i18n = createI18n({ legacy: false, + globalInjection: true, locale: 'en', fallbackLocale: 'en', messages: messages diff --git a/web/i18n/messages/cn.json b/web/i18n/messages/cn.json index de05de7..4571ef1 100644 --- a/web/i18n/messages/cn.json +++ b/web/i18n/messages/cn.json @@ -24,8 +24,38 @@ "label_project": "项目", "label_more": "更多" }, + "profile": { + "label_profile": "个人中心", + "label_modify_information": "修改信息", + "label_change_password": "修改密码", + "label_avatar": "头像", + "label_username": "用户姓名", + "label_email": "邮箱", + "label_old_password": "旧密码", + "label_new_password": "新密码", + "label_confirm_password": "确认密码", + "placeholder_username": "请填写姓名", + "placeholder_email": "请填写邮箱", + "placeholder_old_password": "请输入旧密码", + "placeholder_new_password": "请输入新密码", + "placeholder_confirm_password": "请再次输入新密码", + "message_username_required": "请输入昵称", + "message_old_password_required": "请输入旧密码", + "message_new_password_required": "请输入新密码", + "message_password_confirmation_required": "请再次输入密码", + "message_password_confirmation_diff": "两次密码输入不一致" + }, "errors": { + "label_error": "错误页", "text_back_to_home": "返回首页" } + }, + "common": { + "text": { + "update_success": "修改成功" + }, + "buttons": { + "update": "修改" + } } } \ No newline at end of file diff --git a/web/i18n/messages/en.json b/web/i18n/messages/en.json index ccb38de..1f1783f 100644 --- a/web/i18n/messages/en.json +++ b/web/i18n/messages/en.json @@ -24,8 +24,38 @@ "label_project": "Project", "label_more": "More" }, + "profile": { + "label_profile": "Profile", + "label_modify_information": "Modify your information", + "label_change_password": "Change password", + "label_avatar": "Avatar", + "label_username": "Username", + "label_email": "Email", + "label_old_password": "Old password", + "label_new_password": "New password", + "label_confirm_password": "Password confirmation", + "placeholder_username": "Please fill in your name", + "placeholder_email": "Please fill in your email address", + "placeholder_old_password": "Please enter the old password", + "placeholder_new_password": "Please enter a new password", + "placeholder_confirm_password": "Please enter the confirm password", + "message_username_required": "Please enter username", + "message_old_password_required": "Please enter the old password", + "message_new_password_required": "Please enter a new password", + "message_password_confirmation_required": "Please enter confirm password", + "message_password_confirmation_diff": "Two password inputs are inconsistent" + }, "errors": { + "label_error": "Error", "text_back_to_home": "Back to home" } + }, + "common": { + "text": { + "update_success": "Update success" + }, + "buttons": { + "update": "Update" + } } } \ No newline at end of file diff --git a/web/src/router/routes/index.js b/web/src/router/routes/index.js index 805c541..bfb5a2a 100644 --- a/web/src/router/routes/index.js +++ b/web/src/router/routes/index.js @@ -1,8 +1,11 @@ +import i18n from '~/i18n' +const {t} = i18n.global + const Layout = () => import('@/layout/index.vue') export const basicRoutes = [ { - name: '工作台', + name: t('views.workbench.label_workbench'), path: '/', component: Layout, redirect: '/workbench', // 默认跳转到首页 @@ -10,9 +13,9 @@ export const basicRoutes = [ { path: 'workbench', component: () => import('@/views/workbench/index.vue'), - name: '工作台', + name: t('views.workbench.label_workbench'), meta: { - title: '工作台', + title: t('views.workbench.label_workbench'), icon: 'icon-park-outline:workbench', affix: true, }, @@ -21,7 +24,7 @@ export const basicRoutes = [ meta: { order: 0 }, }, { - name: '个人中心', + name: t('views.profile.label_profile'), path: '/', component: Layout, isHidden: true, @@ -29,9 +32,9 @@ export const basicRoutes = [ { path: 'profile', component: () => import('@/views/profile/index.vue'), - name: '个人中心', + name: t('views.profile.label_profile'), meta: { - title: '个人中心', + title: t('views.profile.label_profile'), icon: 'user', affix: true, }, @@ -45,7 +48,7 @@ export const basicRoutes = [ component: Layout, redirect: '/error-page/404', meta: { - title: '错误页', + title: t('views.errors.label_error'), icon: 'mdi:alert-circle-outline', order: 99, }, diff --git a/web/src/views/profile/index.vue b/web/src/views/profile/index.vue index 2bd51e8..9fd1fb6 100644 --- a/web/src/views/profile/index.vue +++ b/web/src/views/profile/index.vue @@ -1,12 +1,13 @@