@@ -72,16 +72,38 @@ export function getBrowserLocale() {
72
72
// supportedLocalesOf will throw if the locales has a '_' instead of a '-' in it.
73
73
const userLocaleDashed = browserLocale . replaceAll ( '_' , '-' ) ;
74
74
75
- const matchingLocales = Intl . DateTimeFormat . supportedLocalesOf ( userLocaleDashed ) ;
76
-
77
- const mappingTo = matchingLocales ?. [ 0 ] || 'en' ;
78
-
79
- if ( ! mappedBrowserLocaleDisplayed ) {
80
- mappedBrowserLocaleDisplayed = true ;
81
- i18nLog ( `userLocaleDashed: '${ userLocaleDashed } ', mapping to browser locale: ${ mappingTo } ` ) ;
75
+ try {
76
+ let matchingLocales : Array < string > = [ ] ;
77
+ try {
78
+ matchingLocales = Intl . DateTimeFormat . supportedLocalesOf ( userLocaleDashed ) ;
79
+ } catch ( innerError ) {
80
+ // some users have a locale setup with a ':' in it.
81
+ // see https://github.com/oxen-io/session-desktop/issues/3221
82
+ const semiColonIndex = userLocaleDashed . indexOf ( ':' ) ;
83
+ if ( semiColonIndex > - 1 ) {
84
+ matchingLocales = Intl . DateTimeFormat . supportedLocalesOf (
85
+ userLocaleDashed . substring ( 0 , semiColonIndex )
86
+ ) ;
87
+ }
88
+ }
89
+
90
+ const mappingTo = matchingLocales ?. [ 0 ] || 'en' ;
91
+
92
+ if ( ! mappedBrowserLocaleDisplayed ) {
93
+ mappedBrowserLocaleDisplayed = true ;
94
+ i18nLog ( `userLocaleDashed: '${ userLocaleDashed } ', mapping to browser locale: ${ mappingTo } ` ) ;
95
+ }
96
+
97
+ return mappingTo ;
98
+ } catch ( e ) {
99
+ if ( ! mappedBrowserLocaleDisplayed ) {
100
+ mappedBrowserLocaleDisplayed = true ;
101
+ i18nLog (
102
+ `userLocaleDashed: '${ userLocaleDashed } ' was an invalid locale for supportedLocalesOf(). Falling back to 'en'. Error:${ e . message } `
103
+ ) ;
104
+ }
105
+ return 'en' ;
82
106
}
83
-
84
- return mappingTo ;
85
107
}
86
108
87
109
export function setInitialLocale ( crowdinLocaleArg : CrowdinLocale , dictionary : LocalizerDictionary ) {
0 commit comments