Manual:言語

This page is a translated version of the page Manual:Language and the translation is 52% complete.
国際化の説明文書
Manual:MediaWiki architecture#Languages も参照してください (このページに統合すべきかも)

MediaWiki には、さまざまな種類の言語があります:

  • サイトコンテンツの言語$wgLanguageCode に依拠するContentLanguage)は通常、ウィキが存在する限り不変であるべきです。
  • ユーザー インターフェイスの言語$contextSource->getLanguage()、旧来の$wgLang )は、個人設定もしくはURLの &uselang=xyz で変更できますが、これも一般的にはウィキの利用中、同じままです。
  • ページ コンテンツの言語。これはサイトと利用者言語が同じでもページごとに異なることがあります。Title の getPageLanguage() で定義され、ページ コンテンツ (例えば、ウィキテキスト) のソースがどの言語で記述されているかを示します。
    • ページ表示言語ないしはユーザー言語変種とはページコンテンツ言語の言語変種で、ユーザーが選んだものです。 もし表示中のページのページコンテンツ言語の変種であるなら、URLの&variant(または$wgVariantArticlePath )でも(例えばタブのひとつを選んで)設定できます。 Title の getPageViewLanguage() で定義され、提供されるHTMLコンテンツが何語で記述されているのかを示します。

これら3つすべてを指して言語オブジェクトと呼びます。

言語コード

Wikimedia project codeのことではありません。メタのLanguage codesも参照。

言語コードとはMediaWikiがサポートする言語の有効な標準略称であり[1]、用いるコードは言語の標準識別子 (ほぼISO 639-3に準拠し例外は「定着した」ロケール用のISO 639-1準拠の2文字コード)をインターフェイスとコーディングでしばしば提示または要求されます。[2]

下記の例 MediaWiki:Message/ar では、ar が Arabic の言語コードです。

Unicode 標準との一貫性は、特に CLDR との連携において、良好な言語サポートを提供するために必要です。MediaWiki ロケールへの言語追加の要件の 1 つとして、言語が ISO 639-3 コードを持つことが求められています。

Names.php

Names.php is the master registry of languages supported by MediaWiki. This is not the same as languages of which MediaWiki will show l10n (JSON files) nor languages of which MediaWiki knows the names (via CLDR ), mind you!

フォールバック言語

 
フォールバックの連鎖 (Some of the lines shown are inaccurate due to double languages in the fallback. Check if the connection actually exists in the text version)

MediaWiki の一部の言語には「フォールバック連鎖」というものがあります。 これは必要なものが見つからない場合に、MediaWikiが別の言語で表示されるものです。 一例として言語コード frcケイジャン・フランス語)は fr (フランス語)にフォールバックします。 これは言語によってはすべてのメッセージが定義されていない場合があるためです。

言語のフォールバックは、対応する言語の languages/messages/MessagesXX.php ファイル内に記述されています。 例えば MessagesFrc.php です。すべての使用についてコードを検索できます。 この Phabricator コメントに2020年9月からの計画リストもあります。

サイトコンテンツの言語

サイトのコンテンツ言語の閲覧/取得

JavaScript :

mw.config.get( 'wgContentLanguage' );

ユーザーインターフェイスの言語

MediaWiki バージョン:
1.18
既定値
変更する方法
  • Special:Preferences (個人設定)
  • URL で &uselang=zxx の形式で指定する (uselang を参照)
  • URLを設定できる &variant=xy(または $wgVariantArticlePath )は、それがユーザー言語の言語変種である場合に限定
問題
インターフェースのメッセージがフォールバック言語に由来することがありますが、言語を返さないため、各メッセージの実際の言語はわかりません。

ページコンテンツの言語

MediaWiki バージョン:
1.18
既定値
  • 特別ページの言語は $wgLang です。
  • CSS ページおよび JS ページは英語です。
  • MediaWiki 名前空間のページでは、言語は下位ページによって異なります。例えば、MediaWiki:Message/ar はアラビア語 (ar) になり、MediaWiki:Messsage は ContentLanguage になります。
  • その他のページはすべて、既定では ContentLanguage です。
構成
拡張機能は PageContentLanguage フックを使用し、その他のページを一括して変更します。 特別ページ、CSS、JS および MediaWiki 名前空間のページの値はオーバーライドされません。
Translate extensionではページ翻訳機能に利用。一例としてtranslatewiki:Project listの訳文translatewiki:Project list/arを見ると、アラビア語の書字方向は正しく反映され左書き。
MediaWiki バージョン:
1.24
手動でページ言語を変更する
MediaWiki 1.24以降、 Special:PageLanguage でページ言語の選択ができるようになりました。
既定では既定のウィキ言語 (ContentLanguage) であるページのコンテンツ言語を利用者が変更できます。MediaWiki 名前空間にあるページの言語は変更できません。
機能は $wgPageLanguageUseDB = true で有効化する必要があり、 pagelang の許可がウィキ利用者権限グループに付与されていなければなりません(これによって利用者がページ言語の変更を実施できるようになります)。
Changing page language causes the source translation page and its units to be moved to the correct target language. In case the target language translation page already exists, the language change isn't allowed.
Matching API can be found on API:SetPageLanguage .
定義する対象
  • SkinTemplate (外装) ではページの文字表示について <div lang="xyz" dir="ltr/rtl" class="mw-content-ltr/rtl"></div> を追加します。dir属性により書字方向が正しく設定されます。lang属性は常にルートのコード、例えば「de-formal」が与えられたときでも「de」を取ります。
    ファイルページにおいては、ユーザー言語にHTML記述が多いため、設定はImagePage.phpで行います。
  • Parser.phpでは、目次(TOC) の付番や文法を設定するものの、実際にはほとんど関係ありません。そうするだけなら、 parserOptions->setTargetLanguage() を使用してください。
  • 差分テキスト (DifferenceEngine) の書字方向はページコンテンツの言語に設定されます。場合によってはこれが同一ではなく、その場合には $diffEngineObject->setTextLanguage( $code ) を使用できます。
  • 1.19以降、時刻と数字の書式マジックワードも設定します。DIRECTIONMARKは対象ですが、NAMESPACE(E)は、実際にはサイト言語に依存するので対象外です。言語Bを用いるページにおいて言語Aと指定されたテンプレートがあったとしても、そのページでは言語Bでパースされるということに注意してください。
複数言語を用いた単一ページ
理論的には単一のページに複数言語を使うことはサポートされていませんが、単純な <div lang="xyz" dir="ltr/rtl" class="mw-content-ltr/rtl"> タグを使用すれば、他の言語で記述し始めるとマークすることができます。CSSクラスを適用した場合は、dirタグがページの本文言語の値と衝突してもul/ol 一覧とeditsectionは正しく表示されます。しかしながらパーサーで定義する目次(TOC)やマジックワードなどの要素に影響はありません。
ページ言語の閲覧/取得
  • JavaScript: mw.config.get( 'wgPageContentLanguage' ) - 例えばページの変更履歴を閲覧するとき、該当ページの言語を返しますが、変更履歴ページは mw-content-ltr/rtl クラスを持たない点に注意してください。つまり「/wiki/Page」と「/w/index.php?title=Page&action=history」は、どちらも「Page」の言語を返します。 1.19+
  • ページの本文言語はページの情報表示に定義 (action=info、ツールボックスのリンク) 1.21+
  • ページの本文言語はapi.php?action=query&prop=infoを介してAPIで取得 1.22+

コード構造

まず、言語オブジェクトが Language.php にあります。 This object contains all the localisable message strings, as well as other important language-specific settings and custom behavior (uppercasing, lowercasing, printing dates, formatting numbers, direction, custom grammar rules etc.).

The object is constructed from two sources: sub-classed versions of itself (classes) and Message files (messages).

There's also the MessageCache class, which handles input of text via the MediaWiki namespace. Most internationalisation is nowadays done via Manual:メッセージAPI objects and by using the wfMessage() shortcut function, which is defined in includes/GlobalFunctions.php. Legacy code might still be using the old wfMsg*() functions, which are now considered deprecated in favor of the above-mentioned Message objects.

Manual:メッセージAPI も参照してください。

言語オブジェクト

言語オブジェクトを取得する方法が2つあります。 You can use the globals $wgLang and ContentLanguage service (MediaWiki\MediaWikiServices::getContentLanguage) for user interface and content language respectively. For an arbitrary language you can construct an object by using $languageFactory->getLanguage( 'en' ) by replacing en with the code of the language. Dependency Injection を使って、 MediaWiki\Languages\LanguageFactory クラスのオブジェクトである、 $languageFactory を取得できます。 $code が既に言語オブジェクトかもしれない場合、 wfGetLangObj( $code ); を使うこともできます。 コードのリストは includes/languages/data/Names.php にあります。

Language objects are needed for doing language-specific functions, most often to do number, time and date formatting, but also to construct lists and other things. There are multiple layers of caching and merging with #Fallback languages, but the details are irrelevant in normal use.

古いローカル翻訳システム

MediaWiki 1.3.0で、MediaWikiを地域化するための新しいシステムが設置されました。 言語ファイルを編集して開発者に変更の適用を依頼するのではなく、利用者がウィキから直接インターフェース文字列を編集できます。 これは2005年8月時点で使用されているシステムです。 Special:AllMessages で翻訳したいメッセージを見つけて、 MediaWiki: 名前空間にある関連する文字列を編集できます。 編集すると、変更が反映されます。 更新を依頼して、開発者がファイルを確認して更新するのを待つ必要はなくなりました。

ウィキペディアプロジェクトにとっては素晴らしいシステムですが、副作用として、ソフトウェアに搭載される MediaWiki 言語ファイルは完全に最新のものではなくなり、開発者が実際の言語ファイルとメタ上のファイルの同期を維持することが困難になります。

既定の言語ファイルが十分な翻訳済み素材を提供していないことで、2つの問題に直面します:

  1. 長期間更新されていない言語で作成された新しいウィキメディアプロジェクトは、インターフェースの完全な再翻訳を必要とします。
  2. MediaWiki の他の利用者(同一言語のウィキメディアプロジェクトを含む)は未翻訳のインターフェースに取り残されます。 これは特に翻訳者が多くない小規模言語にとっては不幸なことです。

translatewiki.net が広く宣伝され、ほとんどすべての翻訳者に利用されるようになったので、これは大きな問題ではなくなりました。 ローカルな翻訳はまだときどき起こりますが、強く抑えられています。 ローカルメッセージはたいてい削除して、関連する翻訳を translatewiki.net に移動し、ウィキ上にはサイト特有のカスタマイズのみを残す必要があります。特に古いプロジェクトには膨大なバックログがあり、このツールがクリーンアップに役立ちます。

Keeping messages centralised and in sync

English messages are very rarely out of sync with the code. Experience has shown that it's convenient to have all the English messages in the same place. Revising the English text can be done without reference to the code, just like translation can. Programmers sometimes make very poor choices for the default text.

地域化できるもの

So many things are localisable on MediaWiki that not all of them are directly available on translatewiki.net : see translatewiki:Translating:MediaWiki. If something requires a developer intervention on the code, you can request it on Phabricator, or ask at translatewiki:Support if you don't know what to do exactly.

 
言語フォールバックの図式
  • Fallback languages (that is, other more closely related language(s) to use when a translation is not available, instead of the default fallback, which is English)
  • Directionality (left to right or right to left, RTL)
  • Direction mark character depending on RTL
  • Arrow depending on RTL
  • Languages where italics cannot be used
  • Number formatting (comma-ify, i.e. adding or not digits separators; transform digits; transform separators)[3]
  • Truncate (multibyte)
  • Grammar conversions for inflected languages
  • Plural transformations
  • Formatting expiry times[clarification needed]
  • Segmenting for diffs (Chinese)
  • Convert to variants of language (between different orthographies, or scripts)
  • Language specific user preference options
  • Link trails and link prefix - $linkTrail. These are letters that can be glued after/before the closing/opening brackets of a wiki link, but appear rendered on the screen as if part of the link (that is, clickable and in the same colour), e.g.: [[foo]]bar. By default the link trail is "a-z"; you may want to add the accentuated or non-Latin letters used by your language to the list.
  • Language code (preferably used according to the latest RFC in standard BCP 47, currently RFC 5646, with its associated IANA database. Avoid deprecated, grandfathered and private-use codes: look at what they mean in standard ISO 639, and avoid codes assigned to collections/families of languages in ISO 639-5, and ISO 639 codes which were not imported in the IANA database for BCP 47)
  • Type of emphasising
  • The Cite extension has a special page file per language, cite_text-zyx for language code zyx.

Neat functionality:

  • I18N sprintfDate
  • Roman numeral formatting

名前空間

Currently making namespace name translations is disabled on translatewiki.net, so you need to do this yourself in Gerrit, or file a Phabricator task asking for someone else to do it.[4]

To allow custom namespaces introduced by your extension to be translated, create a MyExtension.i18n.namespaces.php file that looks like this:

<?php
/**
 *  Translations of the namespaces introduced by MyExtension.
 *
 * @file
 */

$namespaceNames = [];

//  For wikis where the MyExtension extension is not installed.
if( !defined( 'NS_MYEXTENSION' ) ) {
	define( 'NS_MYEXTENSION', 2510 );
}

if( !defined( 'NS_MYEXTENSION_TALK' ) ) {
	define( 'NS_MYEXTENSION_TALK', 2511 );
}

/** English */
$namespaceNames['en'] = [
	NS_MYEXTENSION => 'MyNamespace',
	NS_MYEXTENSION_TALK => 'MyNamespace_talk',
];

/** Finnish (Suomi) */
$namespaceNames['fi'] = [
	NS_MYEXTENSION => 'Nimiavaruuteni',
	NS_MYEXTENSION_TALK => 'Keskustelu_nimiavaruudestani',
];

Then load it from the extension.json file using ExtensionMessagesFiles like this:

{
	"name": "MyExtension",
	"version": "0.0.1",
	"descriptionmsg": "myextension-desc",
    "ExtensionMessagesFiles": {
		"MyExtensionNamespaces": "MyExtension.i18n.namespaces.php"
	}
}

Now, when a user installs MyExtension on their Finnish (fi) wiki, the custom namespace will be translated into Finnish magically, and the user doesn't need to do a thing!

Also remember to register your extension's namespace(s) on the 拡張機能の既定の名前空間 page.

特別ページの別名

See the manual page for Special pages for up-to-date information. The following does not appear to be valid.


Create a new file for the special page aliases in this format:

<?php
/**
 * Aliases for the MyExtension extension.
 *
 * @file
 * @ingroup Extensions
 */

$aliases = [];

/** English */
$aliases['en'] = [
	'MyExtension' => [ 'MyExtension' ]
];

/** Finnish (Suomi) */
$aliases['fi'] = [
	'MyExtension' => [ 'Lisäosani' ]
];

Then load it from the extension.json file using ExtensionMessagesFiles like this:

{
	"name": "MyExtension",
	"version": "0.0.1",
	"descriptionmsg": "myextension-desc",
    "ExtensionMessagesFiles": {
		"MyExtensionAlias": "MyExtension.i18n.alias.php"
	}
}

When your special page code uses either SpecialPage::getTitleFor( 'MyExtension' ) or $this->getTitle() (in the class that provides Special:MyExtension), the localised alias will be used, if it's available.

名前空間名の別名

Namespace name aliases are additional names which can be used to address existing namespaces. They are rarely needed, but not having them when they are, usually creates havoc in existing wikis.

You need namespace name aliases:

  1. When a language has variants, and these variants spell some namespaces differently, and you want editors to be able to use the variant spellings.

Variants are selectable in the user preferences. Users always see their selected variant, except in wikitext, but when editing or searching, an arbitrary variant can be used.

  1. When an existing wiki's language, fall back language(s), or localisation is changed, with it are changed some namespace names.

So as not to break the links already present in the wiki, that are using the old namespace names, you need to add each of the altered previous namespace names to its namespace name aliases, when, or before, the change is made.

The generic English namespace names are always present as namespace name aliases in all localisations, so you need not, and should not, add those.

Aliases can't be translated on translatewiki.net , but can be requested there or on Bugzilla : see translatewiki:Translating:MediaWiki#Namespace name aliases.

Regional settings

Some linguistic settings vary across geographies; MediaWiki doesn't have a concept of region, it only has languages and language variants.

These settings need to be set once as a language's default, then individual wikis can change them as they wish in their configuration.

時刻と日付の書式

Time and dates are shown on special pages and alike. The default time and date format is used for signatures, so it should be the most used and most widely understood format for users of that language. Also anonymous users see the default format. Registered users can choose other formats in their preferences.

If you are familiar with PHP's time() format, you can try to construct formats yourself. MediaWiki uses a similar format string, with some extra features. If you don't understand the previous sentence, that's OK. You can provide a list of examples for 開発者 .

注記

  1. includes/languages/data/Names.php 参照。
  2. これにもかかわらず、2012年時点で言語コードの検証は未解決の問題です。 2012年8月28日付Niklas Laxström筆 Language validation in MediaWiki (MediaWikiにおける言語の検証)を参照。
  3. These are configured by language in the respective language/classes/LanguageXx.php or language/messages/MessagesXx.php files.
  4. https://gerrit.wikimedia.org/r/211677

関連項目