Extension:CLDR
CLDR Release status: stable |
|
---|---|
Description | Provides functions to localize the names of languages, countries, currencies, and time units based on their language code. |
Author(s) |
|
Latest version | 4.15.0 (Continous updates) |
MediaWiki | 1.30+ |
Database changes | No |
Composer | mediawiki/cldr |
License | GPL-2.0-or-later, data variant of BSD 3-clauses |
Download | Included in Language Extension Bundle or
README |
Example | Translatewiki.net |
master | |
Public wikis using | 6,625 (Ranked 63rd) |
Translate the CLDR extension if it is available at translatewiki.net | |
The CLDR extension contains local language names for different languages, countries, currencies, and time units extracted from CLDR data. See translatewiki:CLDR for information.
Installation
[edit]- Download and move the extracted
cldr
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/cldr - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'cldr' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
If you download from git, change the file from CLDR to cldr.
Updating data
[edit]The CLDR extension comes with data pre-populated in the language files, but if you want to get the latest data from the Unicode Consortium, you'll need to download it from the CLDR site and then run a rebuild script.
Download newest data from CLDR site:
http://www.unicode.org/cldr/repository_access.html
Example (from within the cldr directory):
wget http://www.unicode.org/Public/cldr/latest/core.zip
unzip core.zip -d core
php rebuild.php
Usage and parameters
[edit]Language names
[edit]CLDR defines the class LanguageNames which has a static method, getNames()
.
LanguageNames::getNames
accepts three parameters:
- code - the ISO 639 (see Manual:Language#Language code for details) code of the preferred language to return the list in
- fbMethod - fallback method, it should be set to one of the following:
- LanguageNames::FALLBACK_NATIVE - Missing entries fallback to the native name (default)
- LanguageNames::FALLBACK_NORMAL - Missing entries fallback through the fallback chain
- list - which languages to return. Should be set to one of the following:
- LanguageNames::LIST_MW_SUPPORTED - Only languages that have localization in MediaWiki
- LanguageNames::LIST_MW - All languages that are in
Names.php
(default) - LanguageNames::LIST_MW_AND_CLDR - All languages that are either in MediaWiki or in CLDR
Example
[edit]The language names are best access with MediaWiki core functions:
// Japanisch
$name = Language::fetchLanguageName( 'ja', 'de', 'all' );
Country names
[edit]CLDR defines the class CountryNames
which has a static method, getNames()
.
CountryNames::getNames
accepts one parameter:
- code - the ISO 639 code of the preferred language to return the list in
Example
[edit]The following example sets a variable to the list of all countries in CLDR in French.
if ( is_callable( array( 'CountryNames', 'getNames' ) ) ) {
$countries = CountryNames::getNames( 'fr' );
}
See also
[edit]This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such high-traffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page. |
This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
- Stable extensions
- Extensions with invalid or missing type
- Extensions supporting Composer
- Extensions with unknown license
- Extensions in Wikimedia version control
- GetHumanTimestamp extensions
- LanguageGetTranslatedLanguageNames extensions
- All extensions
- Extensions used on Wikimedia
- Extensions included in Fandom
- Extensions included in Miraheze
- Extensions included in ProWiki
- Extensions included in WikiForge
- Localisation extensions