Skip to content

Commit

Permalink
Merge pull request #12208 from ethereum/error-handling
Browse files Browse the repository at this point in the history
refactor: useLanguagePicker warning and fallback
  • Loading branch information
pettinarip authored Mar 26, 2024
2 parents 43fdc77 + e5857aa commit ca8edb9
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/components/LanguagePicker/useLanguagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,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 @@ -116,10 +118,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 @@ -128,17 +144,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

0 comments on commit ca8edb9

Please sign in to comment.