From 27f99595c0961fdc7123f1cfaf371a08d7ef7e8b Mon Sep 17 00:00:00 2001 From: Paul Wackerow <54227730+wackerow@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:57:25 -0800 Subject: [PATCH 1/2] refactor: rm throw, add console warn and fallback --- .../LanguagePicker/useLanguagePicker.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/LanguagePicker/useLanguagePicker.tsx b/src/components/LanguagePicker/useLanguagePicker.tsx index 5210eb8136a..ad185df9cd4 100644 --- a/src/components/LanguagePicker/useLanguagePicker.tsx +++ b/src/components/LanguagePicker/useLanguagePicker.tsx @@ -88,9 +88,11 @@ export const useLanguagePicker = ( const targetName = i18nConfigTarget || fallbackTarget if (!sourceName || !targetName) { - throw new Error( - "Missing language display name, locale: " + localeOption - ) + console.warn("Missing language display name:", { + localeOption, + sourceName, + targetName, + }) } // English will not have a dataItem @@ -106,10 +108,9 @@ export const useLanguagePicker = ( (dataItem!.words.approved / dataItem!.words.total) * 100 ) || 0 - if (progressData.length === 0) - throw new Error( - "Missing translation progress data; check GitHub action" - ) + if (progressData.length === 0) { + console.warn("Missing translation progress data; check GitHub action") + } const totalWords = progressData[0].words.total @@ -123,8 +124,8 @@ export const useLanguagePicker = ( return { localeOption, approvalProgress, - sourceName, - targetName, + sourceName: sourceName ?? "", + targetName: targetName ?? "", englishName, wordsApproved, isBrowserDefault, From e5857aacfb951666c71df54115ae7a7bd7c3c702 Mon Sep 17 00:00:00 2001 From: Paul Wackerow <54227730+wackerow@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:30:37 -0700 Subject: [PATCH 2/2] refactor: return early if no progressData use localeOption (lang code) fallback for source or target names instead of empty string --- .../LanguagePicker/useLanguagePicker.tsx | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/components/LanguagePicker/useLanguagePicker.tsx b/src/components/LanguagePicker/useLanguagePicker.tsx index ad185df9cd4..5d4d95ff0ea 100644 --- a/src/components/LanguagePicker/useLanguagePicker.tsx +++ b/src/components/LanguagePicker/useLanguagePicker.tsx @@ -108,8 +108,23 @@ export const useLanguagePicker = ( (dataItem!.words.approved / dataItem!.words.total) * 100 ) || 0 - if (progressData.length === 0) { - console.warn("Missing translation progress data; check GitHub action") + const isBrowserDefault = browserLocales.includes(localeOption) + + const returnData: Partial = { + localeOption, + sourceName: sourceName ?? localeOption, + targetName: targetName ?? localeOption, + englishName, + isBrowserDefault, + } + + if (progressData.length < 1) { + console.warn(`Missing translation progress data; check GitHub action`) + return { + ...returnData, + approvalProgress: 0, + wordsApproved: 0, + } as LocaleDisplayInfo } const totalWords = progressData[0].words.total @@ -119,17 +134,11 @@ export const useLanguagePicker = ( ? totalWords || 0 : dataItem?.words.approved || 0 - const isBrowserDefault = browserLocales.includes(localeOption) - return { - localeOption, + ...returnData, approvalProgress, - sourceName: sourceName ?? "", - targetName: targetName ?? "", - englishName, wordsApproved, - isBrowserDefault, - } + } as LocaleDisplayInfo } const displayNames: LocaleDisplayInfo[] =