File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -361,9 +361,25 @@ public function __construct() {
361361 public static function get_main_lang_code ( $ country ) {
362362 if ( I18n::is_extension_loaded () ) {
363363 $ subtags = \ResourceBundle::create ( 'likelySubtags ' , 'ICUDATA ' , false );
364- $ country = \Locale::canonicalize ( 'und_ ' . $ country );
365- $ locale = $ subtags ->get ( $ country ) ? $ subtags ->get ( $ country ) : $ subtags ->get ( 'und ' );
366- return \Locale::getPrimaryLanguage ( $ locale );
364+ if ( $ subtags instanceof \ResourceBundle ) {
365+ // First try
366+ $ locale = $ subtags ->get ( \Locale::canonicalize ( 'und_ ' . $ country ) );
367+ if ( $ locale ) {
368+ return \Locale::getPrimaryLanguage ( $ locale );
369+ }
370+ // Second try
371+ $ locale = $ subtags ->get ( 'und_ ' . $ country );
372+ if ( $ locale ) {
373+ return \Locale::getPrimaryLanguage ( $ locale );
374+ }
375+ // Third try
376+ $ locale = $ subtags ->get ( $ country );
377+ if ( $ locale ) {
378+ return \Locale::getPrimaryLanguage ( $ locale );
379+ }
380+ }
381+ // Fallback
382+ return 'en_US ' ;
367383 }
368384 return '' ;
369385 }
You can’t perform that action at this time.
0 commit comments