Skip to content

Commit

Permalink
Assumes ResourceBundle::create() may return null with likelySubtags…
Browse files Browse the repository at this point in the history
… starting with ICU v74.1.
  • Loading branch information
Pierre-Lannoy committed Nov 22, 2024
1 parent ae20ab4 commit 58f62e3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions includes/system/class-l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,25 @@ public function __construct() {
public static function get_main_lang_code( $country ) {
if ( I18n::is_extension_loaded() ) {
$subtags = \ResourceBundle::create( 'likelySubtags', 'ICUDATA', false );
$country = \Locale::canonicalize( 'und_' . $country );
$locale = $subtags->get( $country ) ? $subtags->get( $country ) : $subtags->get( 'und' );
return \Locale::getPrimaryLanguage( $locale );
if ( $subtags instanceof \ResourceBundle ) {
// First try
$locale = $subtags->get( \Locale::canonicalize( 'und_' . $country ) );
if ( $locale ) {
return \Locale::getPrimaryLanguage( $locale );
}
// Second try
$locale = $subtags->get( 'und_' . $country );
if ( $locale ) {
return \Locale::getPrimaryLanguage( $locale );
}
// Third try
$locale = $subtags->get( $country );
if ( $locale ) {
return \Locale::getPrimaryLanguage( $locale );
}
}
// Fallback
return 'en_US';
}
return '';
}
Expand Down

0 comments on commit 58f62e3

Please sign in to comment.