MediaWiki  master
LanguageCode Class Reference

Methods for dealing with language codes. More...

Static Public Member Functions

static bcp47 ( $code)
 Get the normalised IANA language tag See unit test for examples. More...
 
static bcp47ToInternal (string $code)
 Convert standardized BCP 47 codes to the internal names used by MediaWiki and returned by Language::getCode(). 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 isWellFormedLanguageTag (string $code, bool $lenient=false)
 Returns true if a language code string is a well-formed language tag according to RFC 5646. More...
 
static replaceDeprecatedCodes ( $code)
 Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes. More...
 

Detailed Description

Methods for dealing with language codes.

Since
1.29

Definition at line 27 of file LanguageCode.php.

Member Function Documentation

◆ bcp47()

static LanguageCode::bcp47 (   $code)
static

◆ bcp47ToInternal()

static LanguageCode::bcp47ToInternal ( string  $code)
static

Convert standardized BCP 47 codes to the internal names used by MediaWiki and returned by Language::getCode().

This function should be the inverse of LanguageCode::bcp47(). Note that BCP 47 explicitly states that language codes are case insensitive.

Since LanguageFactory::getLanguage() is pretty generous about accepting aliases (as long as they are lowercased), this function should be equivalent to: LanguageFactory::getLanguage(strtolower($code))->getCode() but (a) better describes the caller's intention, and (b) should be much more efficient in practice.

Parameters
string$codeThe standard BCP-47 language code
Returns
string A MediaWiki-internal code, as returned for example by Language::getCode()
Since
1.40

Definition at line 225 of file LanguageCode.php.

Referenced by MediaWiki\Languages\LanguageFactory\getParentLanguage().

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

Referenced by LanguageConverter\getVarSeparatorPattern().

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

References bcp47().

◆ isWellFormedLanguageTag()

static LanguageCode::isWellFormedLanguageTag ( string  $code,
bool  $lenient = false 
)
static

Returns true if a language code string is a well-formed language tag according to RFC 5646.

This function only checks well-formedness; it doesn't check that language, script or variant codes actually exist in the repositories.

Based on regexes by Mark Davis of the Unicode Consortium: https://github.com/unicode-org/icu/blob/37e295627156bc334e1f1e88807025fac984da0e/icu4j/main/tests/translit/src/com/ibm/icu/dev/test/translit/langtagRegex.txt

Parameters
string$code
bool$lenientWhether to allow '_' as separator. The default is only '-'.
Returns
bool
Since
1.39

Definition at line 273 of file LanguageCode.php.

Referenced by Language\isWellFormedLanguageTag(), SvgHandler\parseParamString(), and SvgHandler\validateParam().

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

Referenced by bcp47(), and LanguageConverter\validateVariant().


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