From 960580fd62f84a1c0468d4c6ace6d0b0b123d7b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com>
Date: Mon, 29 Jan 2024 18:59:17 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=8Ai18n=E7=9A=84=E4=B8=9C?=
=?UTF-8?q?=E8=A5=BF=E6=94=BE=E5=88=B0=20i18n.vue?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/locales/index.ts | 4 ++++
src/pages/index/i18n.vue | 10 ++++++++--
src/pages/index/index.vue | 12 ++----------
3 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/locales/index.ts b/src/locales/index.ts
index 1e97ddf..1a03901 100644
--- a/src/locales/index.ts
+++ b/src/locales/index.ts
@@ -29,6 +29,10 @@ const i18n = createI18n({
* @param { string } localeKey 多语言的key,eg: "app.name"
*/
export const translate = (localeKey: string) => {
+ if (!localeKey) {
+ console.error(`[i18n] Function translate(), localeKey param is required`)
+ return ''
+ }
const locale = getLocale()
const message = messages[locale]
if (Object.keys(message).includes(localeKey)) {
diff --git a/src/pages/index/i18n.vue b/src/pages/index/i18n.vue
index 3009474..fcd0275 100644
--- a/src/pages/index/i18n.vue
+++ b/src/pages/index/i18n.vue
@@ -1,5 +1,3 @@
-{{ $t('app.name') }}
-
{
"style": {
@@ -7,3 +5,11 @@
}
}
+
+{{ $t('app.name') }}
+
+
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 431ac1b..8316b96 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -2,8 +2,8 @@
{
style: {
- // "navigationStyle": "custom",
- navigationBarTitleText: '%app.name%',
+ navigationStyle: 'custom',
+ navigationBarTitleText: '首页',
},
}
@@ -12,7 +12,6 @@
class="bg-white h-full overflow-hidden pt-2 px-4"
:style="{ marginTop: safeAreaInsets?.top + 'px' }"
>
- {{ $t('app.name') }}
@@ -38,15 +37,8 @@