46 'be-x-old' =>
'be-tarask',
49 'zh-classical' =>
'lzh',
50 'zh-min-nan' =>
'nan',
88 'de-formal' =>
'de-x-formal',
90 'en-rtl' =>
'en-x-rtl',
91 'es-formal' =>
'es-x-formal',
92 'hu-formal' =>
'hu-x-formal',
93 'map-bms' =>
'jv-x-bms',
96 'nl-informal' =>
'nl-x-informal',
97 'roa-tara' =>
'nap-x-tara',
98 'simple' =>
'en-simple',
100 'sr-el' =>
'sr-Latn',
107 'zh-cn' =>
'zh-Hans-CN',
108 'zh-sg' =>
'zh-Hans-SG',
109 'zh-my' =>
'zh-Hans-MY',
110 'zh-tw' =>
'zh-Hant-TW',
111 'zh-hk' =>
'zh-Hant-HK',
112 'zh-mo' =>
'zh-Hant-MO',
128 return self::$deprecatedLanguageCodeMapping;
145 foreach ( self::$deprecatedLanguageCodeMapping as $code => $ignore ) {
146 $result[$code] = self::bcp47( $code );
148 foreach ( self::$nonstandardLanguageCodeMapping as $code => $ignore ) {
149 $result[$code] = self::bcp47( $code );
165 return self::$deprecatedLanguageCodeMapping[$code] ?? $code;
178 public static function bcp47( $code ) {
179 $code = self::replaceDeprecatedCodes( strtolower( $code ) );
180 if ( isset( self::$nonstandardLanguageCodeMapping[$code] ) ) {
181 $code = self::$nonstandardLanguageCodeMapping[$code];
183 $codeSegment = explode(
'-', $code );
185 foreach ( $codeSegment as $segNo => $seg ) {
187 if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) ==
'x' ) {
188 $codeBCP[$segNo] = strtolower( $seg );
190 } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
191 $codeBCP[$segNo] = strtoupper( $seg );
193 } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
194 $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
197 $codeBCP[$segNo] = strtolower( $seg );
200 $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 array $deprecatedLanguageCodeMapping
Mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date,...
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 array $nonstandardLanguageCodeMapping
Mapping of non-standard language codes used in MediaWiki to standardized BCP 47 codes.
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.