39 private const DEPRECATED_LANGUAGE_CODE_MAPPING = [
44 'be-x-old' =>
'be-tarask',
47 'zh-classical' =>
'lzh',
48 'zh-min-nan' =>
'nan',
78 private const NON_STANDARD_LANGUAGE_CODE_MAPPING = [
85 'de-formal' =>
'de-x-formal',
87 'en-rtl' =>
'en-x-rtl',
88 'es-formal' =>
'es-x-formal',
89 'hu-formal' =>
'hu-x-formal',
90 'map-bms' =>
'jv-x-bms',
93 'nl-informal' =>
'nl-x-informal',
94 'roa-tara' =>
'nap-x-tara',
95 'simple' =>
'en-simple',
104 'zh-cn' =>
'zh-Hans-CN',
105 'zh-sg' =>
'zh-Hans-SG',
106 'zh-my' =>
'zh-Hans-MY',
107 'zh-tw' =>
'zh-Hant-TW',
108 'zh-hk' =>
'zh-Hant-HK',
109 'zh-mo' =>
'zh-Hant-MO',
125 return self::DEPRECATED_LANGUAGE_CODE_MAPPING;
142 foreach ( self::DEPRECATED_LANGUAGE_CODE_MAPPING as $code => $ignore ) {
145 foreach ( self::NON_STANDARD_LANGUAGE_CODE_MAPPING as $code => $ignore ) {
162 return self::DEPRECATED_LANGUAGE_CODE_MAPPING[$code] ?? $code;
175 public static function bcp47( $code ) {
177 if ( isset( self::NON_STANDARD_LANGUAGE_CODE_MAPPING[$code] ) ) {
178 $code = self::NON_STANDARD_LANGUAGE_CODE_MAPPING[$code];
180 $codeSegment = explode(
'-', $code );
182 foreach ( $codeSegment as $segNo => $seg ) {
184 if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) ==
'x' ) {
185 $codeBCP[$segNo] = strtolower( $seg );
187 } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
188 $codeBCP[$segNo] = strtoupper( $seg );
190 } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
191 $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
194 $codeBCP[$segNo] = strtolower( $seg );
197 $langCode = implode(
'-', $codeBCP );
Methods for dealing with language codes.
static getNonstandardLanguageCodeMapping()
Returns a mapping of non-standard language codes used by (current and previous version of) MediaWiki,...
static replaceDeprecatedCodes( $code)
Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date,...
static getDeprecatedCodeMapping()
Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up...
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.