Skip to content

Commit ca8edb9

Browse files
authored
Merge pull request #12208 from ethereum/error-handling
refactor: useLanguagePicker warning and fallback
2 parents 43fdc77 + e5857aa commit ca8edb9

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/components/LanguagePicker/useLanguagePicker.tsx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ export const useLanguagePicker = (
9898
const targetName = i18nConfigTarget || fallbackTarget
9999

100100
if (!sourceName || !targetName) {
101-
throw new Error(
102-
"Missing language display name, locale: " + localeOption
103-
)
101+
console.warn("Missing language display name:", {
102+
localeOption,
103+
sourceName,
104+
targetName,
105+
})
104106
}
105107

106108
// English will not have a dataItem
@@ -116,10 +118,24 @@ export const useLanguagePicker = (
116118
(dataItem!.words.approved / dataItem!.words.total) * 100
117119
) || 0
118120

119-
if (progressData.length === 0)
120-
throw new Error(
121-
"Missing translation progress data; check GitHub action"
122-
)
121+
const isBrowserDefault = browserLocales.includes(localeOption)
122+
123+
const returnData: Partial<LocaleDisplayInfo> = {
124+
localeOption,
125+
sourceName: sourceName ?? localeOption,
126+
targetName: targetName ?? localeOption,
127+
englishName,
128+
isBrowserDefault,
129+
}
130+
131+
if (progressData.length < 1) {
132+
console.warn(`Missing translation progress data; check GitHub action`)
133+
return {
134+
...returnData,
135+
approvalProgress: 0,
136+
wordsApproved: 0,
137+
} as LocaleDisplayInfo
138+
}
123139

124140
const totalWords = progressData[0].words.total
125141

@@ -128,17 +144,11 @@ export const useLanguagePicker = (
128144
? totalWords || 0
129145
: dataItem?.words.approved || 0
130146

131-
const isBrowserDefault = browserLocales.includes(localeOption)
132-
133147
return {
134-
localeOption,
148+
...returnData,
135149
approvalProgress,
136-
sourceName,
137-
targetName,
138-
englishName,
139150
wordsApproved,
140-
isBrowserDefault,
141-
}
151+
} as LocaleDisplayInfo
142152
}
143153

144154
const displayNames: LocaleDisplayInfo[] =

0 commit comments

Comments
 (0)