From 2b22e9042fe588bf3dfbbaeba39c92a8377c5aa4 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Mon, 13 May 2024 09:01:19 -0600 Subject: [PATCH] Case insensitivity for locale query parameter (also handling - => _), see https://github.com/phetsims/joist/issues/963 --- js/initialize-globals.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/js/initialize-globals.js b/js/initialize-globals.js index 25f09df33..eef7dba89 100644 --- a/js/initialize-globals.js +++ b/js/initialize-globals.js @@ -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; + } } } }