Skip to content

Commit

Permalink
Case insensitivity for locale query parameter (also handling - => _),…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed May 13, 2024
1 parent 00cd035 commit 2b22e90
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions js/initialize-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,11 +974,25 @@

let locale = phet.chipper.locale;

if ( locale && locale.length === 3 ) {
for ( const candidateLocale of Object.keys( phet.chipper.localeData ) ) {
if ( phet.chipper.localeData[ candidateLocale ].locale3 === locale ) {
locale = candidateLocale;
break;
if ( locale ) {
if ( locale.length < 5 ) {
locale = locale.toLowerCase();
}
else {
locale = locale.replace( /-/, '_' );

const parts = locale.split( '_' );
if ( parts.length === 2 ) {
locale = parts[ 0 ].toLowerCase() + '_' + parts[ 1 ].toUpperCase();
}
}

if ( locale.length === 3 ) {
for ( const candidateLocale of Object.keys( phet.chipper.localeData ) ) {
if ( phet.chipper.localeData[ candidateLocale ].locale3 === locale ) {
locale = candidateLocale;
break;
}
}
}
}
Expand Down

0 comments on commit 2b22e90

Please sign in to comment.