MediaWiki  1.34.0
LanguageCode Class Reference

Methods for dealing with language codes. More...

Static Public Member Functions

static bcp47 ( $code)
 Get the normalised IETF language tag See unit test for examples. More...
 
static getDeprecatedCodeMapping ()
 Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes. More...
 
static getNonstandardLanguageCodeMapping ()
 Returns a mapping of non-standard language codes used by (current and previous version of) MediaWiki, mapped to standard BCP 47 names. More...
 
static replaceDeprecatedCodes ( $code)
 Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes. More...
 

Static Private Attributes

static array $deprecatedLanguageCodeMapping
 Mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes. More...
 
static array $nonstandardLanguageCodeMapping
 Mapping of non-standard language codes used in MediaWiki to standardized BCP 47 codes. More...
 

Detailed Description

Methods for dealing with language codes.

Since
1.29

Definition at line 28 of file LanguageCode.php.

Member Function Documentation

◆ bcp47()

static LanguageCode::bcp47 (   $code)
static

Get the normalised IETF language tag See unit test for examples.

See mediawiki.language.bcp47 for the JavaScript implementation.

Parameters
string$codeThe language code.
Returns
string A language code complying with BCP 47 standards.
Since
1.31

Definition at line 178 of file LanguageCode.php.

References replaceDeprecatedCodes().

Referenced by SkinTemplate\buildContentNavigationUrls(), ImagePage\createXmlOptionStringForLanguage(), ApiQueryLanguageinfo\execute(), MediaWiki\Rest\ResponseFactory\formatMessage(), Language\getHtmlCode(), FeedItem\getLanguage(), SkinTemplate\getLanguages(), getNonstandardLanguageCodeMapping(), CoreParserFunctions\language(), and MediaWiki\Preferences\DefaultPreferencesFactory\profilePreferences().

◆ getDeprecatedCodeMapping()

static LanguageCode::getDeprecatedCodeMapping ( )
static

Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes.

This array is merged into $wgDummyLanguageCodes in Setup.php, along with the fake language codes 'qqq' and 'qqx', which are used internally by MediaWiki's localisation system.

Returns
string[]
Since
1.29

Definition at line 127 of file LanguageCode.php.

References $deprecatedLanguageCodeMapping.

◆ getNonstandardLanguageCodeMapping()

static LanguageCode::getNonstandardLanguageCodeMapping ( )
static

Returns a mapping of non-standard language codes used by (current and previous version of) MediaWiki, mapped to standard BCP 47 names.

This array is exported to JavaScript to ensure mediawiki.language.bcp47 stays in sync with LanguageCode::bcp47().

Returns
string[]
Since
1.32

Definition at line 143 of file LanguageCode.php.

References bcp47().

Referenced by ResourceLoaderLanguageDataModule\getData().

◆ replaceDeprecatedCodes()

static LanguageCode::replaceDeprecatedCodes (   $code)
static

Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes.

Other values will returned unchanged.

Parameters
string$codeOld language code
Returns
string New language code
Since
1.30

Definition at line 164 of file LanguageCode.php.

Referenced by bcp47(), and User\loadOptions().

Member Data Documentation

◆ $deprecatedLanguageCodeMapping

array LanguageCode::$deprecatedLanguageCodeMapping
staticprivate
Initial value:
= [
'als' => 'gsw',
'bat-smg' => 'sgs',
'be-x-old' => 'be-tarask',
'fiu-vro' => 'vro',
'roa-rup' => 'rup',
'zh-classical' => 'lzh',
'zh-min-nan' => 'nan',
'zh-yue' => 'yue',
]

Mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes.

These may or may not be valid BCP 47 codes; they are included here because MediaWiki renamed these particular codes at some point.

Mapping from deprecated MediaWiki-internal language code to replacement MediaWiki-internal language code.

Since
1.30
See also
https://meta.wikimedia.org/wiki/Special_language_codes

Definition at line 41 of file LanguageCode.php.

Referenced by getDeprecatedCodeMapping().

◆ $nonstandardLanguageCodeMapping

array LanguageCode::$nonstandardLanguageCodeMapping
staticprivate

Mapping of non-standard language codes used in MediaWiki to standardized BCP 47 codes.

These are not deprecated (yet?): IANA may eventually recognize the subtag, in which case the -x- infix could be removed, or else we could rename the code in MediaWiki, in which case they'd move up to the above mapping of deprecated codes.

As a rule, we preserve all distinctions made by MediaWiki internally. For example, de-formal becomes de-x-formal instead of just de because MediaWiki distinguishes de-formal from de (for example, for interface translations). Similarly, BCP 47 indicates that kk-Cyrl SHOULD not be used because it "typically does not add information", but in our case MediaWiki LanguageConverter distinguishes kk (render content in a mix of Kurdish variants) from kk-Cyrl (convert content to be uniformly Cyrillic). As the BCP 47 requirement is a SHOULD not a MUST, kk-Cyrl is a valid code, although some validators may emit a warning note.

Mapping from nonstandard MediaWiki-internal codes to BCP 47 codes

Since
1.32
See also
https://meta.wikimedia.org/wiki/Special_language_codes
https://phabricator.wikimedia.org/T125073

Definition at line 81 of file LanguageCode.php.


The documentation for this class was generated from the following file: