拓展:CLDR

This page is a translated version of the page Extension:CLDR and the translation is 35% complete.
MediaWiki扩展手冊
OOjs UI icon advanced-invert.svg
CLDR
發布狀態: 穩定版本
ExampleOfCLDRExtension.png
实现 解析器函数
描述 提供根據語言識別碼在地化語言、國家/地區、貨幣或時間單位名稱的功能。
作者
最新版本 4.11.0 (持續更新)
MediaWiki 1.30+
数据庫更改
Composer mediawiki/cldr
许可协议 GPL-2.0-or-later, data variant of BSD 3-clauses
下載 包括於語言拓展包
README
示例 Translatewiki.net
master
翻譯CLDR扩展,若在translatewiki.net可用

检查使用和版本矩阵。

CLDR擴展包含從CLDR資料中提取的不同語言、國家/地區、貨幣和時間單位的本地語言名稱。 参见translatewiki:CLDR以获取更多信息。

安装

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

如果是從git下載,則請將檔案從CLDR更改為cldr。

編輯資料

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 Manual:Language#Language code for details) code of the preferred language to return the list in
  2. 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
  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 - All languages that are in Names.php (default)
    • 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' );
}


参见