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

fix(app): do not crash when you get a "C" locale #16716

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,31 @@
useEffect(() => {
if (systemLanguage != null) {
// prefer match entire locale, then match just language e.g. zh-Hant and zh-CN
const matchedSystemLanguageOption =
LANGUAGES.find(lng => lng.value === systemLanguage) ??
LANGUAGES.find(
lng =>
new Intl.Locale(lng.value).language ===
new Intl.Locale(systemLanguage).language
)
const matchSystemLanguage: () => string | null = () => {

Check failure on line 86 in app/src/organisms/Desktop/SystemLanguagePreferenceModal/index.tsx

View workflow job for this annotation

GitHub Actions / js checks

Type '() => { name: string; value: Language; } | null | undefined' is not assignable to type '() => string | null'.

Check failure on line 86 in app/src/organisms/Desktop/SystemLanguagePreferenceModal/index.tsx

View workflow job for this annotation

GitHub Actions / js checks

Type '() => { name: string; value: Language; } | null | undefined' is not assignable to type '() => string | null'.
try {
return (
LANGUAGES.find(lng => lng.value === systemLanguage) ??
LANGUAGES.find(
lng =>
new Intl.Locale(lng.value).language ===
new Intl.Locale(systemLanguage).language
)
)
} catch (error: unknown) {
// Sometimes the language that we get from the shell will not be something
// js i18n can understand. Specifically, some linux systems will have their
// locale set to "C" (https://www.gnu.org/software/libc/manual/html_node/Standard-Locales.html)
// and that will cause Intl.Locale to throw. In this case, we'll treat it as
// unset and fall back to our default.
console.log(`Failed to search languages: ${error}`)
return null
}
}
const matchedSystemLanguageOption = matchSystemLanguage()

if (matchedSystemLanguageOption != null) {
// initial current option: set to detected system language
setCurrentOption(matchedSystemLanguageOption)

Check failure on line 110 in app/src/organisms/Desktop/SystemLanguagePreferenceModal/index.tsx

View workflow job for this annotation

GitHub Actions / js checks

Argument of type 'string' is not assignable to parameter of type 'SetStateAction<DropdownOption>'.

Check failure on line 110 in app/src/organisms/Desktop/SystemLanguagePreferenceModal/index.tsx

View workflow job for this annotation

GitHub Actions / js checks

Argument of type 'string' is not assignable to parameter of type 'SetStateAction<DropdownOption>'.
if (showBootModal) {
// for boot modal temp change app display language based on initial system locale
void i18n.changeLanguage(systemLanguage)
Expand Down
Loading