Skip to content

Commit e5857aa

Browse files
committed
refactor: return early if no progressData
use localeOption (lang code) fallback for source or target names instead of empty string
1 parent 27f9959 commit e5857aa

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/components/LanguagePicker/useLanguagePicker.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,23 @@ export const useLanguagePicker = (
108108
(dataItem!.words.approved / dataItem!.words.total) * 100
109109
) || 0
110110

111-
if (progressData.length === 0) {
112-
console.warn("Missing translation progress data; check GitHub action")
111+
const isBrowserDefault = browserLocales.includes(localeOption)
112+
113+
const returnData: Partial<LocaleDisplayInfo> = {
114+
localeOption,
115+
sourceName: sourceName ?? localeOption,
116+
targetName: targetName ?? localeOption,
117+
englishName,
118+
isBrowserDefault,
119+
}
120+
121+
if (progressData.length < 1) {
122+
console.warn(`Missing translation progress data; check GitHub action`)
123+
return {
124+
...returnData,
125+
approvalProgress: 0,
126+
wordsApproved: 0,
127+
} as LocaleDisplayInfo
113128
}
114129

115130
const totalWords = progressData[0].words.total
@@ -119,17 +134,11 @@ export const useLanguagePicker = (
119134
? totalWords || 0
120135
: dataItem?.words.approved || 0
121136

122-
const isBrowserDefault = browserLocales.includes(localeOption)
123-
124137
return {
125-
localeOption,
138+
...returnData,
126139
approvalProgress,
127-
sourceName: sourceName ?? "",
128-
targetName: targetName ?? "",
129-
englishName,
130140
wordsApproved,
131-
isBrowserDefault,
132-
}
141+
} as LocaleDisplayInfo
133142
}
134143

135144
const displayNames: LocaleDisplayInfo[] =

0 commit comments

Comments
 (0)