mirror of https://github.com/msgbyte/tailchat
feat(mobile): add i18n support in rn
parent
6ab48b02da
commit
5668e091ed
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "self:">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
@ -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>
|
@ -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();
|
@ -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"
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"core.addServer": "添加服务器",
|
||||||
|
"core.selectedServer": "选中服务器",
|
||||||
|
"core.deleteServer": "删除服务器",
|
||||||
|
"core.inputServerUrl": "输入服务器地址",
|
||||||
|
"core.confirm": "确认",
|
||||||
|
"core.invalidUrl": "输入不是一个有效的url",
|
||||||
|
"core.addServerError": "添加服务器失败, 可能输入的地址不是一个Tailchat服务地址",
|
||||||
|
"core.foregroundServiceTip": "持续保持服务正常运行, 关闭后可能无法正常接受到消息推送",
|
||||||
|
"core.foregroundServiceStopAction": "停止前台服务"
|
||||||
|
}
|
Loading…
Reference in New Issue