Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: useLanguagePicker warning and fallback #12208

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/components/LanguagePicker/useLanguagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -106,10 +108,24 @@ 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"
)
const isBrowserDefault = browserLocales.includes(localeOption)

const returnData: Partial<LocaleDisplayInfo> = {
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

Expand All @@ -118,17 +134,11 @@ export const useLanguagePicker = (
? totalWords || 0
: dataItem?.words.approved || 0

const isBrowserDefault = browserLocales.includes(localeOption)

return {
localeOption,
...returnData,
approvalProgress,
sourceName,
targetName,
englishName,
wordsApproved,
isBrowserDefault,
}
} as LocaleDisplayInfo
}

const displayNames: LocaleDisplayInfo[] =
Expand Down
Loading