Skip to content

Commit 58f62e3

Browse files
committed
Assumes ResourceBundle::create() may return null with likelySubtags starting with ICU v74.1.
1 parent ae20ab4 commit 58f62e3

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

includes/system/class-l10n.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)