Open main menu
This page is a translated version of the page Extension:CLDR and the translation is 14% complete.

Other languages:
English • ‎dansk • ‎español • ‎русский • ‎中文 • ‎日本語
MediaWiki扩展手册
OOjs UI icon advanced.svg
CLDR
发布状态: 稳定版
ExampleOfCLDRExtension.png
实现 Parser function
描述 Provides functions to localize the names of languages, countries, currencies, and time units based on their language code.
作者
最新版本 4.3.0 (CLDR 29) (Continous updates)
MediaWiki 1.30+
数据更新
Composer mediawiki/cldr
许可协议 GPL-2.0+, data variant of BSD 3-clauses
下载 Included in Language Extension Bundle or
README
例子 Translatewiki.net
翻译CLDR扩展如果在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.

Contents

Installation

  • 下载文件,并将其放置在您extensions/文件夹中的cldr目录内。
  • 将下列代码放置在您的LocalSettings.php的底部:
    wfLoadExtension( 'cldr' );
    
  •   完成 – 在您的wiki上导航至Special:Version,以验证扩展已成功安装。

致使用MediaWiki 1.26或更早版本的用户:

上面的说明介绍的是安装此扩展的新方法,它使用wfLoadExtension()。 如果您需要在早期版本(MediaWiki 1.26和更早版本)中安装此扩展,而不是wfLoadExtension( 'cldr' );,您需要使用:

require_once "$IP/extensions/cldr/cldr.php";

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

Usage and parameters

Language names

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

  1. code - the ISO 639 (see here for details) 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

Example

The language names are best access with MediaWiki core functions:

// Japanisch
$name = Language::fetchLanguageName( 'ja', 'de', 'all' );

国家名称

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

示例

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

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

示例

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


参见