@@ -20,6 +20,29 @@ export function getTimeLocaleDictionary() {
2020 return ( timeLocaleMap as Record < string , Locale > ) [ getBrowserLocale ( ) ] || timeLocaleMap . en ;
2121}
2222
23+ /**
24+ * Some users have a locale setup with a ':' in it.
25+ * When this happens, the full locale (i.e. the part with the "_") can sometimes be on the left, sometimes on the right.
26+ * This function will always return the part with the "_" if found, otherwise the full locale.
27+ */
28+ export function keepFullLocalePart ( locale : string ) {
29+ const firstUnderscore = locale . indexOf ( '_' ) ;
30+ const firstDash = locale . indexOf ( '-' ) ;
31+ const firstSemiColon = locale . indexOf ( ':' ) ;
32+ if ( firstSemiColon === - 1 ) {
33+ return locale ;
34+ }
35+ const firstUnderscoreOrDash = Math . max ( firstUnderscore , firstDash ) ;
36+
37+ if ( firstSemiColon > firstUnderscoreOrDash ) {
38+ // the semicolon is after the underscore, so we return the start of the string (de_DE:en we return de_DE)
39+ return locale . substring ( 0 , firstSemiColon ) ;
40+ }
41+
42+ // the semicolon is before the underscore, so we return the end of the string (in en:de_DE wew return de_DE)
43+ return locale . substring ( firstSemiColon + 1 ) ;
44+ }
45+
2346/**
2447 * Returns the current locale as supported by Session (i.e. one generated by crowdin)
2548 */
@@ -36,7 +59,7 @@ export function getCrowdinLocale(): CrowdinLocale {
3659 * Returns the closest supported locale by the browser.
3760 */
3861export function getBrowserLocale ( ) {
39- const browserLocale = process . env . LANGUAGE || getCrowdinLocale ( ) || 'en' ;
62+ const browserLocale = keepFullLocalePart ( process . env . LANGUAGE || getCrowdinLocale ( ) || 'en' ) ;
4063
4164 // supportedLocalesOf will throw if the locales has a '_' instead of a '-' in it.
4265 const userLocaleDashed = browserLocale . replaceAll ( '_' , '-' ) ;
0 commit comments