MediaWiki REL1_31
LanguageCode.php
Go to the documentation of this file.
1<?php
39 // Note that als is actually a valid ISO 639 code (Tosk Albanian), but it
40 // was previously used in MediaWiki for Alsatian, which comes under gsw
41 'als' => 'gsw',
42 'bat-smg' => 'sgs',
43 'be-x-old' => 'be-tarask',
44 'fiu-vro' => 'vro',
45 'roa-rup' => 'rup',
46 'zh-classical' => 'lzh',
47 'zh-min-nan' => 'nan',
48 'zh-yue' => 'yue',
49 ];
50
63 public static function getDeprecatedCodeMapping() {
64 return self::$deprecatedLanguageCodeMapping;
65 }
66
77 public static function replaceDeprecatedCodes( $code ) {
78 if ( isset( self::$deprecatedLanguageCodeMapping[$code] ) ) {
79 return self::$deprecatedLanguageCodeMapping[$code];
80 }
81 return $code;
82 }
83
94 public static function bcp47( $code ) {
95 $codeSegment = explode( '-', $code );
96 $codeBCP = [];
97 foreach ( $codeSegment as $segNo => $seg ) {
98 // when previous segment is x, it is a private segment and should be lc
99 if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
100 $codeBCP[$segNo] = strtolower( $seg );
101 // ISO 3166 country code
102 } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
103 $codeBCP[$segNo] = strtoupper( $seg );
104 // ISO 15924 script code
105 } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
106 $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
107 // Use lowercase for other cases
108 } else {
109 $codeBCP[$segNo] = strtolower( $seg );
110 }
111 }
112 $langCode = implode( '-', $codeBCP );
113 return $langCode;
114 }
115}
Methods for dealing with language codes.
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 bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:865