From 3e25327590054dfd3353636ff1681b8662dd6846 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 19:14:01 +0800
Subject: [PATCH] feat: i18n
---
src/locales/index.ts | 2 +-
src/pages/index/i18n.vue | 40 ++++++++++++++++++++++++++++++++++++++--
src/utils/index.ts | 8 ++++----
3 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/src/locales/index.ts b/src/locales/index.ts
index 1a03901..258ceb5 100644
--- a/src/locales/index.ts
+++ b/src/locales/index.ts
@@ -9,7 +9,7 @@ const messages = {
}
console.log(uni.getLocale())
-const getLocale = () => {
+export const getLocale = () => {
const browserLang = uni.getLocale()
if (Object.keys(messages).includes(browserLang)) {
return browserLang
diff --git a/src/pages/index/i18n.vue b/src/pages/index/i18n.vue
index fcd0275..285644f 100644
--- a/src/pages/index/i18n.vue
+++ b/src/pages/index/i18n.vue
@@ -6,10 +6,46 @@
}
-{{ $t('app.name') }}
+
+ {{ $t('app.name') }}
+
+ 切换语言
+
+
+
+
+
+
+
+
+
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 27ead93..47c72b8 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -6,8 +6,8 @@ import { translate as t } from '@/locales/index'
export const testI18n = () => {
console.log(t('app.name'))
// 下面同样生效
- // uni.showModal({
- // title: 'i18n 测试',
- // content: t('app.name'),
- // })
+ uni.showModal({
+ title: 'i18n 测试',
+ content: t('app.name'),
+ })
}