Fixes blank screen in browsers that don't support Intl.DisplayNames (#36847)

This commit is contained in:
diondiondion 2025-11-12 12:11:48 +01:00 committed by GitHub
parent 9f3573d446
commit f303f3458d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 10 deletions

View File

@ -169,9 +169,13 @@ const localeOptionsSelector = createSelector(
}, },
}; };
// Use the default locale as a target to translate language names. // Use the default locale as a target to translate language names.
const intlLocale = new Intl.DisplayNames(intl.locale, { const intlLocale =
type: 'language', // Intl.DisplayNames can be undefined in old browsers
}); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Intl.DisplayNames &&
(new Intl.DisplayNames(intl.locale, {
type: 'language',
}) as Intl.DisplayNames | undefined);
for (const { translations } of rules) { for (const { translations } of rules) {
for (const locale in translations) { for (const locale in translations) {
if (langs[locale]) { if (langs[locale]) {
@ -179,7 +183,7 @@ const localeOptionsSelector = createSelector(
} }
langs[locale] = { langs[locale] = {
value: locale, value: locale,
text: intlLocale.of(locale) ?? locale, text: intlLocale?.of(locale) ?? locale,
}; };
} }
} }

View File

@ -129,17 +129,21 @@ export const statusPageUrl = getMeta('status_page_url');
export const sso_redirect = getMeta('sso_redirect'); export const sso_redirect = getMeta('sso_redirect');
export const termsOfServiceEnabled = getMeta('terms_of_service_enabled'); export const termsOfServiceEnabled = getMeta('terms_of_service_enabled');
const displayNames = new Intl.DisplayNames(getMeta('locale'), { const displayNames =
type: 'language', // Intl.DisplayNames can be undefined in old browsers
fallback: 'none', // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
languageDisplay: 'standard', Intl.DisplayNames &&
}); (new Intl.DisplayNames(getMeta('locale'), {
type: 'language',
fallback: 'none',
languageDisplay: 'standard',
}) as Intl.DisplayNames | undefined);
export const languages = initialState?.languages.map((lang) => { export const languages = initialState?.languages.map((lang) => {
// zh-YUE is not a valid CLDR unicode_language_id // zh-YUE is not a valid CLDR unicode_language_id
return [ return [
lang[0], lang[0],
displayNames.of(lang[0].replace('zh-YUE', 'yue')) ?? lang[1], displayNames?.of(lang[0].replace('zh-YUE', 'yue')) ?? lang[1],
lang[2], lang[2],
]; ];
}); });