Skip to content

Commit d85fe5b

Browse files
committed
fix: fallback to Intl.DisplayNames
if output of t() is not found for that language
1 parent 8ae7e73 commit d85fe5b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/components/LanguagePicker/useLanguagePicker.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ export const useLanguagePicker = (
7171
const fallbackSource =
7272
intlSource !== localeOption ? intlSource : englishName
7373
const i18nKey = "language-" + localeOption.toLowerCase()
74-
const i18nSource = t(i18nKey)
75-
const sourceName = i18nSource === i18nKey ? fallbackSource : i18nSource
74+
const i18nSource = t(i18nKey) // Falls back to English namespace if not found
75+
76+
// If i18nSource (fetched from `language-{locale}` in current namespace)
77+
// is not translated (output === englishName), or not available
78+
// (output === i18nKey), use the Intl.DisplayNames result as fallback
79+
const sourceName = [i18nKey, englishName].includes(i18nSource)
80+
? fallbackSource
81+
: i18nSource
7682

7783
// Get "target" display name (Language choice displayed in that language)
7884
const fallbackTarget = new Intl.DisplayNames([localeOption], {

0 commit comments

Comments
 (0)