Extension:CLDR
CLDR Release status: stable |
|||
---|---|---|---|
Implementation | Parser function | ||
Description | Provides functions to localize the names of languages, countries, currencies, and time units based on their language code. | ||
Author(s) | Niklas Laxström, Kaldari | ||
Latest version | 4.0.0 (CLDR 24) (2013-09-19) | ||
MediaWiki | 1.12+ | ||
Database changes | No | ||
License | GNU General Public License 2.0 | ||
Download | Included in Language Extension Bundle or
README |
||
Example | Translatewiki.net | ||
|
|||
Translate the CLDR extension if possible |
|||
Check usage and version matrix; code metrics |
The CLDR extension contains local language names for different languages, countries, currencies, and time units extracted from CLDR data; see translatewiki:CLDR for information.
Contents
Installation[edit | edit source]
- Download and extract the files in a directory called
cldr
in yourextensions/
folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository using:
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/cldr.git
- Add the following code at the bottom of your LocalSettings.php:
require_once( "$IP/extensions/cldr/cldr.php" );
- Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.
Updating data[edit | edit source]
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 | edit source]
Language names[edit | edit source]
CLDR defines the class LanguageNames which has a static method, getNames(). LanguageNames::getNames accepts three parameters:
- code - the ISO 639 code of the preferred language to return the list in
- fbMethod - fallback method. Should be set to one of the following:
- LanguageNames::FALLBACK_NATIVE (default): Missing entries fallback to the native name
- 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 (default): All languages that are in Names.php
- LanguageNames::LIST_MW_AND_CLDR: All languages that are either in MediaWiki or in CLDR
Example[edit | edit source]
The following example sets a variable to the list of all languages in MediaWiki and CLDR in English.
if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { $languages = LanguageNames::getNames( 'en' , LanguageNames::FALLBACK_NORMAL, LanguageNames::LIST_MW_AND_CLDR ); } else { // If we need to display something, use this as fallback $languages = Language::getLanguageNames( false ); }
Country names[edit | edit source]
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 | edit source]
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' ); }
Currency names[edit | edit source]
CLDR defines the class CurrencyNames which has a static method, getNames(). CurrencyNames::getNames accepts one parameter:
- code - the ISO 639 code of the preferred language to return the list in
Example[edit | edit source]
The following example sets a variable to the list of all currencies in CLDR in German.
if ( is_callable( array( 'CurrencyNames', 'getNames' ) ) ) { $currencies = CurrencyNames::getNames( 'de' ); }
See also[edit | edit source]
![]() |
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. |