Extension:CLDR

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
CLDR

Release status: stable

Implementation Parser function
Description Provides functions to localize the names of languages, countries, and currencies based on their language code.
Author(s) Niklas Laxström, Kaldari
Last version 3.0.0 (CLDR 2.0.1) (2011-02-02)
MediaWiki 1.12+
Database changes no
License GPL 2.0
Download Download snapshot
Subversion [Help]

Browse source code
View code changes

README
CHANGELOG

Example Translatewiki.net
Hooks used
LanguageGetTranslatedLanguageNames

Check usage (experimental)

The CLDR extension contains local language names for different languages, countries, and currencies extracted from CLDR data.

Contents

[edit] Installation

  1. Download the files from SVN or download a snapshot. Choose the version that matches your version of MediaWiki.
  2. Create a directory cldr in your $IP/extensions directory.
  3. Extract the files to this $IP/extensions/cldr directory.
  4. Add
    require_once( "$IP/extensions/cldr/cldr.php" );
    to the bottom of LocalSettings.php.
  5. Installation can now be verified through Special:Version of your wiki.

[edit] Updating data

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/1.8.0/core.zip
unzip core.zip -d core
php rebuild.php

[edit] Usage and parameters

[edit] Language names

CLDR defines the class LanguageNames which has a static method, getNames(). LanguageNames::getNames accepts three parameters:

  1. code - the ISO 639 code of the preferred language to return the list in
  2. 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
  3. 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

[edit] Example

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 );
}

[edit] Country names

CLDR defines the class CountryNames which has a static method, getNames(). CountryNames::getNames accepts one parameter:

  1. code - the ISO 639 code of the preferred language to return the list in

[edit] Example

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' );
}

[edit] Currency names

CLDR defines the class CurrencyNames which has a static method, getNames(). CurrencyNames::getNames accepts one parameter:

  1. code - the ISO 639 code of the preferred language to return the list in

[edit] Example

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' );
}
Note: CLDR includes a very large number of currencies, including many that are no longer in use.

[edit] See also


Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox