-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -106,10 +108,9 @@ 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" | ||
) | ||
if (progressData.length === 0) { | ||
console.warn("Missing translation progress data; check GitHub action") | ||
} | ||
|
||
const totalWords = progressData[0].words.total | ||
|
||
|
@@ -123,8 +124,8 @@ export const useLanguagePicker = ( | |
return { | ||
localeOption, | ||
approvalProgress, | ||
sourceName, | ||
targetName, | ||
sourceName: sourceName ?? "", | ||
targetName: targetName ?? "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pettinarip Seeing your comment here... I went with this approach to avoid using mutable variables, sticking with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we should fallback to default locale or something else. Not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wouldn't break anything, but it would just render without a name... I switched this to fallback to its language code. |
||
englishName, | ||
wordsApproved, | ||
isBrowserDefault, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this one again, I think we can probably keep this error. It should never throw as long as there is translation progress data available... if not, we should let the build break. cc: @pettinarip Curious your thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've to disagree on that. This condition is inside a
useEffect
. It will never be checked at build time/server side. If it is ever checked, then it will be on client side, creating bad ux since it will make the app crash (unless we are catching that error and failing gracefully).However, I hear you, it would be nice to have that type of check at build time.
And the change to use
console.warn
is ok I guess but its not doing anything. Shouldn't we return something else here? given that in the next line we are accessing itprogressData[0].words.total
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay yeah, that makes sense, thanks
I think we should... I can update this to return early in this case, and pass everything but the
approvalProgress
andwordsApproved
. We can also uselocaleOption
(Lang
type) as the fallback for the source or target names... this means a language that failed this for whatever reason would just show the language code instead of an empty string.Will push a patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes more sense 👍🏼