From 697eb96260b85028053ebe776b9db93d610f2515 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 26 Sep 2024 16:56:20 +1000 Subject: [PATCH 1/3] fix: fallback to en if supportedLocalesOf throws --- ts/util/i18n/shared.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ts/util/i18n/shared.ts b/ts/util/i18n/shared.ts index 353c4c2984..6c0f9392c6 100644 --- a/ts/util/i18n/shared.ts +++ b/ts/util/i18n/shared.ts @@ -72,16 +72,26 @@ export function getBrowserLocale() { // supportedLocalesOf will throw if the locales has a '_' instead of a '-' in it. const userLocaleDashed = browserLocale.replaceAll('_', '-'); - const matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(userLocaleDashed); - - const mappingTo = matchingLocales?.[0] || 'en'; - - if (!mappedBrowserLocaleDisplayed) { - mappedBrowserLocaleDisplayed = true; - i18nLog(`userLocaleDashed: '${userLocaleDashed}', mapping to browser locale: ${mappingTo}`); + try { + const matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(userLocaleDashed); + + const mappingTo = matchingLocales?.[0] || 'en'; + + if (!mappedBrowserLocaleDisplayed) { + mappedBrowserLocaleDisplayed = true; + i18nLog(`userLocaleDashed: '${userLocaleDashed}', mapping to browser locale: ${mappingTo}`); + } + + 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'; } - - return mappingTo; } export function setInitialLocale(crowdinLocaleArg: CrowdinLocale, dictionary: LocalizerDictionary) { From 714ee46b3154ed1792ffaeed89dfac94979f3799 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 26 Sep 2024 17:03:05 +1000 Subject: [PATCH 2/3] chore: bump Session to 1.14.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c6fbc49fe..0639684950 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "session-desktop", "productName": "Session", "description": "Private messaging from your desktop", - "version": "1.14.0", + "version": "1.14.1", "license": "GPL-3.0", "author": { "name": "Oxen Labs", From 2a185350bb2e039256c000d5735615ceed4b7af5 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 26 Sep 2024 17:20:54 +1000 Subject: [PATCH 3/3] fix: getBrowserLocale: strip to semicolon if found --- ts/util/i18n/shared.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ts/util/i18n/shared.ts b/ts/util/i18n/shared.ts index 6c0f9392c6..cffdc3da7e 100644 --- a/ts/util/i18n/shared.ts +++ b/ts/util/i18n/shared.ts @@ -73,7 +73,19 @@ export function getBrowserLocale() { const userLocaleDashed = browserLocale.replaceAll('_', '-'); try { - const matchingLocales = Intl.DateTimeFormat.supportedLocalesOf(userLocaleDashed); + let matchingLocales: Array = []; + 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';