fix: fallback to en if supportedLocalesOf throws

pull/3224/head
Audric Ackermann 1 year ago
parent a92dbfe59a
commit 697eb96260
No known key found for this signature in database

@ -72,6 +72,7 @@ export function getBrowserLocale() {
// supportedLocalesOf will throw if the locales has a '_' instead of a '-' in it.
const userLocaleDashed = browserLocale.replaceAll('_', '-');
try {
const matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(userLocaleDashed);
const mappingTo = matchingLocales?.[0] || 'en';
@ -82,6 +83,15 @@ export function getBrowserLocale() {
}
return mappingTo;
} catch (e) {
if (!mappedBrowserLocaleDisplayed) {
mappedBrowserLocaleDisplayed = true;
i18nLog(
`userLocaleDashed: '${userLocaleDashed}' was an invalid locale for supportedLocalesOf(). Falling back to 'en'. Error:${e.message} `
);
}
return 'en';
}
}
export function setInitialLocale(crowdinLocaleArg: CrowdinLocale, dictionary: LocalizerDictionary) {

Loading…
Cancel
Save