MediaWiki master
|
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. | |
static | bcp47ToInternal ( $code) |
Convert standardized BCP 47 codes to the internal names used by MediaWiki and returned by Language::getCode(). | |
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 | isWellFormedLanguageTag (string $code, bool $lenient=false) |
Returns true if a language code string is a well-formed language tag according to RFC 5646. | |
static | normalizeNonstandardCodeAndWarn (string $code) |
We want to eventually require valid BCP-47 codes on HTTP and HTML APIs (where the standards require it). | |
static | replaceDeprecatedCodes ( $code) |
Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes. | |
|
static |
Get the normalised IANA language tag See unit test for examples.
See mediawiki.language.bcp47 for the JavaScript implementation.
string | $code | The language code. |
Definition at line 191 of file LanguageCode.php.
References MediaWiki\Language\LanguageCode\replaceDeprecatedCodes().
Referenced by MediaWiki\Language\LanguageCode\getNonstandardLanguageCodeMapping().
|
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.
string | Bcp47Code | $code | The standard BCP-47 language code |
Definition at line 234 of file LanguageCode.php.
|
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 SetupDynamicConfig.php, along with the fake language codes 'qqq' and 'qqx', which are used internally by MediaWiki's localisation system.
Definition at line 137 of file LanguageCode.php.
|
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().
Definition at line 153 of file LanguageCode.php.
References MediaWiki\Language\LanguageCode\bcp47().
|
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
string | $code | |
bool | $lenient | Whether to allow '_' as separator. The default is only '-'. |
Definition at line 313 of file LanguageCode.php.
|
static |
We want to eventually require valid BCP-47 codes on HTTP and HTML APIs (where the standards require it).
This will "prefer" to interpret the given $code as BCP-47, but if a mediawiki internal code is provided, it will map it to the proper BCP-47 code. We don't emit a logged warning on this path yet, but we intend to in the future.
string | $code | A "language code" provided from an HTTP or HTML API, presumed to be BCP-47 |
Definition at line 286 of file LanguageCode.php.
|
static |
Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date, current language codes.
Other values will be returned unchanged.
string | $code | Old language code |
Definition at line 177 of file LanguageCode.php.
Referenced by MediaWiki\Language\LanguageCode\bcp47().