MediaWiki REL1_32
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.
 
static getDeprecatedCodeMapping ()
 Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes.
 
static getNonstandardLanguageCodeMapping ()
 Returns a mapping of non-standard language codes used by (current and previous version of) MediaWiki, mapped to standard BCP 47 names.
 
static replaceDeprecatedCodes ( $code)
 Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes.
 

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.
 
static array $nonstandardLanguageCodeMapping
 Mapping of non-standard language codes used in MediaWiki to standardized BCP 47 codes.
 

Detailed Description

Methods for dealing with language codes.

Todo:
Move some of the code-related static methods out of Language into this class
Since
1.29

Definition at line 29 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 182 of file LanguageCode.php.

References $code, and as.

Referenced by 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 128 of file LanguageCode.php.

◆ 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 144 of file LanguageCode.php.

References $code, and as.

◆ 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 165 of file LanguageCode.php.

References $code.

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 42 of file LanguageCode.php.

◆ $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 82 of file LanguageCode.php.


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