Skip to content

Commit

Permalink
fix: getBrowserLocale: strip to semicolon if found
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Sep 26, 2024
1 parent 714ee46 commit 2a18535
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ts/util/i18n/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@ export function getBrowserLocale() {
const userLocaleDashed = browserLocale.replaceAll('_', '-');

try {
const matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(userLocaleDashed);
let matchingLocales: Array<string> = [];
try {
matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(userLocaleDashed);
} catch (innerError) {
// some users have a locale setup with a ':' in it.
// see https://github.com/oxen-io/session-desktop/issues/3221
const semiColonIndex = userLocaleDashed.indexOf(':');
if (semiColonIndex > -1) {
matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(
userLocaleDashed.substring(0, semiColonIndex)
);
}
}

const mappingTo = matchingLocales?.[0] || 'en';

Expand Down

0 comments on commit 2a18535

Please sign in to comment.