From ca5c8aaec1db7ffc330f50fcdc14400e06ad6f54 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Wed, 1 Jun 2022 16:00:24 +0800 Subject: [PATCH] fix(ui): add i18n formater for zh-CN list (#1009) add i18n formater for zh-CN list --- packages/phrases/src/locales/zh-cn.ts | 8 ++++---- packages/ui/src/i18n/init.ts | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/phrases/src/locales/zh-cn.ts b/packages/phrases/src/locales/zh-cn.ts index 366a91d20..d303e054e 100644 --- a/packages/phrases/src/locales/zh-cn.ts +++ b/packages/phrases/src/locales/zh-cn.ts @@ -29,9 +29,9 @@ const translation = { confirm_password: '确认密码', }, secondary: { - sign_in_with: '通过 {{methods, list(type: disjunction;)}} 登录', + sign_in_with: '通过 {{methods, list(type: disjunction;), zhOrSpaces}} 登录', social_bind_with: - 'Already have an account? Sign in to bind {{methods, list(type: disjunction;)}} with your social identity.', + '绑定到已有账户? 使用 {{methods, list(type: disjunction;), zhOrSpaces}} 登录并绑定。', }, action: { sign_in: '登录', @@ -67,8 +67,8 @@ const translation = { resend_after_seconds: '在 {{ seconds }} 秒后重发', resend_passcode: '重发验证码', continue_with: '通过以下方式继续', - create_account_id_exists: '{{ type }}为 {{ value }} 的账号已存在,您要登录吗?', - sign_in_id_does_not_exists: '{{ type }}为 {{ value }} 的账号不存在,您要创建一个新账号吗?', + create_account_id_exists: '{{type}}为 {{ value }} 的账号已存在,您要登录吗?', + sign_in_id_does_not_exists: '{{type}}为 {{ value }} 的账号不存在,您要创建一个新账号吗?', bind_account_title: '绑定 Logto 账号', social_create_account: 'No account? You can create a new account and bind.', social_bind_account: 'Already have an account? Sign in to bind it with your social identity.', diff --git a/packages/ui/src/i18n/init.ts b/packages/ui/src/i18n/init.ts index 54a87aa34..9724372af 100644 --- a/packages/ui/src/i18n/init.ts +++ b/packages/ui/src/i18n/init.ts @@ -18,7 +18,18 @@ const initI18n = async (languageSettings?: LanguageInfo) => { ? { ...baseOptions, lng: languageSettings.fixedLanguage } : baseOptions; - return i18next.use(initReactI18next).use(LanguageDetector).init(options); + const i18n = i18next.use(initReactI18next).use(LanguageDetector).init(options); + + // @ts-expect-error - i18next doesn't have a type definition for this. called after i18next is initialized + i18next.services.formatter.add('zhOrSpaces', (value: string, lng) => { + if (lng !== 'zh-CN') { + return value; + } + + return value.replaceAll(/或/g, ' 或 '); + }); + + return i18n; }; export default initI18n;