Steps to replicate the issue (include links if applicable):
- Use 'zh-Hant-TW' in HTTP Accept-Language header
- Check the UI language
What happens?:
- It failed to map BCP 47 language code 'zh-hant-tw' as MediaWiki internal language code 'zh-tw'
What should have happened instead?:
- It should handle BCP 47 language codes correctly
Software version (skip for WMF-hosted wikis like Wikipedia):
- Site: https://translatewiki.net
- MediaWiki: 1.41.0-alpha
- UniversalLanguageSelector: 2023-04-26
Other information (browser name/version, screenshots, etc.):
includes/Hooks.php#L273-300
/** * @param float[] $preferred * @return string */ protected function getDefaultLanguage( array $preferred ) { $supported = $this->languageNameUtils ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ); // look for a language that is acceptable to the client // and known to the wiki. foreach ( $preferred as $code => $weight ) { if ( isset( $supported[$code] ) ) { return $code; } } // Some browsers might only send codes like de-de. // Try with bare code. foreach ( $preferred as $code => $weight ) { $parts = explode( '-', $code, 2 ); $code = $parts[0]; if ( isset( $supported[$code] ) ) { return $code; } } return ''; }