From 5668e091edbabed6c8d54dfbf339cf2a1535fdd0 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 28 Mar 2023 14:40:56 +0800 Subject: [PATCH] feat(mobile): add i18n support in rn --- client/mobile/ios/Podfile.lock | 6 ++ .../ios/Tailchat.xcodeproj/project.pbxproj | 1 + .../contents.xcworkspacedata | 7 ++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ client/mobile/package.json | 2 + client/mobile/src/Entry.tsx | 20 +++-- client/mobile/src/lib/i18n/index.ts | 33 +++++++ .../mobile/src/lib/i18n/translations/en.json | 12 +++ .../mobile/src/lib/i18n/translations/zh.json | 11 +++ client/mobile/src/lib/notifications/index.ts | 5 +- client/mobile/yarn.lock | 87 ++++++++++++++++++- 11 files changed, 180 insertions(+), 12 deletions(-) create mode 100644 client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 client/mobile/src/lib/i18n/index.ts create mode 100644 client/mobile/src/lib/i18n/translations/en.json create mode 100644 client/mobile/src/lib/i18n/translations/zh.json diff --git a/client/mobile/ios/Podfile.lock b/client/mobile/ios/Podfile.lock index 9e1f83b3..dac12621 100644 --- a/client/mobile/ios/Podfile.lock +++ b/client/mobile/ios/Podfile.lock @@ -430,6 +430,8 @@ PODS: - React-Core - RNGestureHandler (2.9.0): - React-Core + - RNLocalize (2.2.6): + - React-Core - RNNotifee (7.4.0): - React-Core - RNNotifee/NotifeeCore (= 7.4.0) @@ -533,6 +535,7 @@ DEPENDENCIES: - ReactNativeUiLib (from `../node_modules/react-native-ui-lib`) - "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)" - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) + - RNLocalize (from `../node_modules/react-native-localize`) - "RNNotifee (from `../node_modules/@notifee/react-native`)" - RNReanimated (from `../node_modules/react-native-reanimated`) - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) @@ -636,6 +639,8 @@ EXTERNAL SOURCES: :path: "../node_modules/@react-native-async-storage/async-storage" RNGestureHandler: :path: "../node_modules/react-native-gesture-handler" + RNLocalize: + :path: "../node_modules/react-native-localize" RNNotifee: :path: "../node_modules/@notifee/react-native" RNReanimated: @@ -697,6 +702,7 @@ SPEC CHECKSUMS: ReactNativeUiLib: 8d3804947431a465a69f09c5e785c988314612a9 RNCAsyncStorage: 8616bd5a58af409453ea4e1b246521bb76578d60 RNGestureHandler: 071d7a9ad81e8b83fe7663b303d132406a7d8f39 + RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81 RNNotifee: da8dcf09f079ea22f46e239d7c406e10d4525a5f RNReanimated: cc5e3aa479cb9170bcccf8204291a6950a3be128 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 diff --git a/client/mobile/ios/Tailchat.xcodeproj/project.pbxproj b/client/mobile/ios/Tailchat.xcodeproj/project.pbxproj index 9a440192..9343447e 100644 --- a/client/mobile/ios/Tailchat.xcodeproj/project.pbxproj +++ b/client/mobile/ios/Tailchat.xcodeproj/project.pbxproj @@ -218,6 +218,7 @@ knownRegions = ( en, Base, + "zh-Hans", ); mainGroup = 83CBB9F61A601CBA00E9B192; productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; diff --git a/client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/client/mobile/package.json b/client/mobile/package.json index 8c60d8e6..448a285e 100644 --- a/client/mobile/package.json +++ b/client/mobile/package.json @@ -14,6 +14,7 @@ "test": "jest" }, "dependencies": { + "@formatjs/intl": "^2.6.9", "@notifee/react-native": "^7.4.0", "@react-native-async-storage/async-storage": "^1.17.11", "immer": "^9.0.19", @@ -26,6 +27,7 @@ "react-native-config": "^1.5.0", "react-native-gesture-handler": "^2.9.0", "react-native-getui": "^1.1.42", + "react-native-localize": "^2.2.6", "react-native-reanimated": "^2.14.4", "react-native-ui-lib": "^6.29.1", "react-native-webview": "^11.26.1", diff --git a/client/mobile/src/Entry.tsx b/client/mobile/src/Entry.tsx index 7b55a583..9577e4b9 100644 --- a/client/mobile/src/Entry.tsx +++ b/client/mobile/src/Entry.tsx @@ -11,6 +11,7 @@ import { ActionSheet, } from 'react-native-ui-lib'; import { isValidUrl } from './lib/utils'; +import { translate } from './lib/i18n'; export const Entry: React.FC = React.memo(() => { const { serverList, selectServer, addServer, removeServer } = @@ -40,16 +41,19 @@ export const Entry: React.FC = React.memo(() => { ); })} - setDialogVisible(true)} /> + setDialogVisible(true)} + /> setSelectedServer('')} destructiveButtonIndex={0} options={[ { - label: '删除服务器', + label: translate('core.deleteServer'), onPress: () => { removeServer(selectedServer); }, @@ -64,7 +68,7 @@ export const Entry: React.FC = React.memo(() => { onDismiss={() => setDialogVisible(false)} > - 输入服务器地址: + {translate('core.inputServerUrl')}: { />