diff --git a/includes/system/class-l10n.php b/includes/system/class-l10n.php index b7ff868..a12a2ee 100644 --- a/includes/system/class-l10n.php +++ b/includes/system/class-l10n.php @@ -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 ''; }