From 147dad1673f639b6a3843fdd8da622b43a0b47fd Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Wed, 14 Sep 2022 17:46:12 +0800 Subject: [PATCH] fix(i18): fallback to `zh_hant` only if `en` is nullish --- src/common/utils/translate.ts | 4 +++- src/components/Dialogs/ReviseArticleDialog/index.tsx | 2 +- .../Notice/CommentNotice/CircleNewBroadcastNotice.tsx | 2 +- src/views/ArticleDetail/EditMode/Header/index.tsx | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/utils/translate.ts b/src/common/utils/translate.ts index 54dd673a2f..f0f2b4f280 100644 --- a/src/common/utils/translate.ts +++ b/src/common/utils/translate.ts @@ -52,5 +52,7 @@ export const translate = ({ lang, ...props }: TranslateArgs): string => { translations = { zh_hant, zh_hans, en } } - return translations[lang || 'zh_hant'] || translations.zh_hant + const translation = translations[lang || 'zh_hant'] + + return typeof translation === 'string' ? translation : translations.zh_hant } diff --git a/src/components/Dialogs/ReviseArticleDialog/index.tsx b/src/components/Dialogs/ReviseArticleDialog/index.tsx index 981c0a2da1..3271bcb7dc 100644 --- a/src/components/Dialogs/ReviseArticleDialog/index.tsx +++ b/src/components/Dialogs/ReviseArticleDialog/index.tsx @@ -55,7 +55,7 @@ export const ReviseArticleDialog = ({ children, revisionCountLeft }: Props) => {

- + {revisionCountLeft} { diff --git a/src/views/ArticleDetail/EditMode/Header/index.tsx b/src/views/ArticleDetail/EditMode/Header/index.tsx index 77e4e7187c..527341e138 100644 --- a/src/views/ArticleDetail/EditMode/Header/index.tsx +++ b/src/views/ArticleDetail/EditMode/Header/index.tsx @@ -114,7 +114,7 @@ const EditModeHeader = ({ {revisionCountLeft}