From d995c6ed43c856d55ed16040051b9597379e12b5 Mon Sep 17 00:00:00 2001 From: Dawn_Ocean <1785590531@qq.com> Date: Thu, 7 Mar 2024 14:21:55 +0800 Subject: [PATCH] add localization for tab-bar --- src/custom-tab-bar/index.tsx | 13 +++++++------ src/plain-text/TabBar.ts | 17 +++++++++++++++++ src/plain-text/index.ts | 6 +++++- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/plain-text/TabBar.ts diff --git a/src/custom-tab-bar/index.tsx b/src/custom-tab-bar/index.tsx index b48d76f..c8c2fcc 100644 --- a/src/custom-tab-bar/index.tsx +++ b/src/custom-tab-bar/index.tsx @@ -3,19 +3,20 @@ import { AtTabBar } from 'taro-ui'; import Taro from '@tarojs/taro'; import 'taro-ui/dist/style/index.scss'; import './index.scss'; +import pt from '@/plain-text'; const navList: Array = [ { pagePath: '/pages/index/index', - text: '主页', + text: pt.get().tabBar.indexText, }, { pagePath: '/pages/repair/repair', - text: '维修', + text: pt.get().tabBar.repairText, }, { pagePath: '/pages/user/user', - text: '我的', + text: pt.get().tabBar.userText, }, ]; @@ -24,15 +25,15 @@ export default class Index extends Component { selected: 0, tabList: [ { - title: '主页', + title: pt.get().tabBar.indexText, iconType: 'home', }, { - title: '维修', + title: pt.get().tabBar.repairText, iconType: 'settings', }, { - title: '我的', + title: pt.get().tabBar.userText, iconType: 'user', }, ], diff --git a/src/plain-text/TabBar.ts b/src/plain-text/TabBar.ts new file mode 100644 index 0000000..6947afd --- /dev/null +++ b/src/plain-text/TabBar.ts @@ -0,0 +1,17 @@ +export interface TabBarText { + indexText: string; + repairText: string; + userText: string; +} + +export const tabBarZhCn: TabBarText = { + indexText: '主页', + repairText: '维修', + userText: '我的', +}; + +export const tabBarEnUs: TabBarText = { + indexText: 'Home', + repairText: 'Repair', + userText: 'Account', +}; diff --git a/src/plain-text/index.ts b/src/plain-text/index.ts index 14c6bf6..def2cee 100644 --- a/src/plain-text/index.ts +++ b/src/plain-text/index.ts @@ -1,27 +1,31 @@ import { PageFooterText, pageFooterZhCn, pageFooterEnUs } from './PageFooter'; import { MainPageText, mainPageZhCn, mainPageEnUs } from './MainPage'; import { UserPageText, userPageZhCn, userPageEnUs } from './UserPage'; +import { TabBarText, tabBarEnUs, tabBarZhCn } from './TabBar'; interface TextRecord { pageFooter: PageFooterText; mainPage: MainPageText; userPage: UserPageText; + tabBar: TabBarText; } const textZhCn: TextRecord = { pageFooter: pageFooterZhCn, mainPage: mainPageZhCn, userPage: userPageZhCn, + tabBar: tabBarZhCn, }; const textEnUs: TextRecord = { pageFooter: pageFooterEnUs, mainPage: mainPageEnUs, userPage: userPageEnUs, + tabBar: tabBarEnUs, }; // type Lang = 'zh_CN' | 'en_US' | ...; -type Lang = 'zh_CN' | 'en_US'; +export type Lang = 'zh_CN' | 'en_US'; class PlainText { private readonly textZhCn: TextRecord;