-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): add i18n support in rn
- Loading branch information
1 parent
6ab48b0
commit 5668e09
Showing
11 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
client/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...t/mobile/ios/Tailchat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as RNLocalize from 'react-native-localize'; | ||
import { createIntl, createIntlCache } from '@formatjs/intl'; | ||
import { I18nManager } from 'react-native'; | ||
|
||
const translations = { | ||
en: require('./translations/en.json'), | ||
zh: require('./translations/zh.json'), | ||
} as const; | ||
|
||
type Translation = keyof typeof translations; | ||
|
||
const fallback = { languageTag: 'en', isRTL: false }; | ||
|
||
const { languageTag, isRTL } = | ||
RNLocalize.findBestAvailableLanguage(Object.keys(translations)) ?? fallback; | ||
|
||
I18nManager.forceRTL(isRTL); | ||
|
||
const intl = createIntl( | ||
{ | ||
defaultLocale: 'en', | ||
locale: languageTag, | ||
messages: translations[languageTag as Translation], | ||
}, | ||
createIntlCache() | ||
); | ||
|
||
type TranslationParams = Parameters<(typeof intl)['formatMessage']>[1]; | ||
|
||
export const translate = (key: string, params?: TranslationParams) => | ||
intl | ||
.formatMessage({ id: key, defaultMessage: translations.en[key] }, params) | ||
.toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"core.addServer": "Add Server", | ||
"core.selectedServer": "Selected Server", | ||
"core.deleteServer": "Delete Server", | ||
"core.inputServerUrl": "Input Server Url", | ||
"core.confirm": "Confirm", | ||
"core.invalidUrl": "Input is not a valid url", | ||
"core.addServerError": "Failed to add server, maybe the address entered is not a Tailchat service address", | ||
"core.foregroundServiceTip": "Continue to keep the service running normally, and may not be able to receive message pushes after closing", | ||
"core.foregroundServiceStopAction": "Stop Foreground Service" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"core.addServer": "添加服务器", | ||
"core.selectedServer": "选中服务器", | ||
"core.deleteServer": "删除服务器", | ||
"core.inputServerUrl": "输入服务器地址", | ||
"core.confirm": "确认", | ||
"core.invalidUrl": "输入不是一个有效的url", | ||
"core.addServerError": "添加服务器失败, 可能输入的地址不是一个Tailchat服务地址", | ||
"core.foregroundServiceTip": "持续保持服务正常运行, 关闭后可能无法正常接受到消息推送", | ||
"core.foregroundServiceStopAction": "停止前台服务" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters