Manual:言語
- Manual:MediaWiki architecture#Languages も参照してください (このページに統合すべきかも)
MediaWiki には、さまざまな種類の言語があります:
- サイトの本文の言語(
$wgLanguageCode
に依拠するContentLanguage
)は通常、ウィキが存在する限り不変であるべきです。- サイト本文の言語の変種 ($wgDefaultLanguageVariant ) は LanguageConverter がその言語で実装されているとき、既定の変種です。
- ユーザー インターフェイスの言語($contextSource->getLanguage()、旧来の
$wgLang
)は、個人設定もしくはURLの&uselang=xyz
で変更できますが、これも一般的にはウィキの利用中、同じままです。 - ページ コンテンツの言語。これはサイトと利用者言語が同じでもページごとに異なることがあります。Title の getPageLanguage() で定義され、ページ コンテンツ (例えば、ウィキテキスト) のソースがどの言語で記述されているかを示します。
- ページ表示言語ないしはユーザー言語の変種とはページの本文言語の変種で、ユーザーが選んだものです。これももし表示中のページのページ本文言語の変種であるなら、設定は変更でき、URLの
&variant
(または$wgVariantArticlePath
を例えばタブのひとつを選んで指定できます。定義はTitleのgetPageViewLanguage()にあり、HTMLを解析して本文の記述言語を示します。
- ページ表示言語ないしはユーザー言語の変種とはページの本文言語の変種で、ユーザーが選んだものです。これももし表示中のページのページ本文言語の変種であるなら、設定は変更でき、URLの
これら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!
フォールバック言語
MediaWiki の言語版により「代替方式」を用意しています。もし使用言語で必要な定義がない時は、MediaWikiが別の言語で表示されます。一例として言語コードfrc
(ケイジャン・フランス語)はfr
(フランス語)で代替します。この処置は言語版によって定義していないメッセージを補うためです。
言語の代替は、対応する言語の languages/messages/MessagesXX.php
ファイル内に記述されています。
For instance MessagesFrc.php. You can search the code for all uses. There is also a plain list from 2020年9月 in this Phabricator comment.
サイトのコンテンツ用言語
サイトのコンテンツ言語の閲覧/取得
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 |
- Manually changing page language
- Page language selection is now achievable with help of Special:PageLanguage since MediaWiki 1.24.
- Users can change content language of a page which is by default the default Wiki language (
ContentLanguage
). Language of pages in the MediaWiki namespace can't be changed.
- The feature needs to be enabled with
$wgPageLanguageUseDB = true
and thepagelang
permission must be granted to a wiki user rights group (who can then perform page language changes).
- 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()です。
- diff 文の書字方向 (DifferenceEngine) はページの本文言語に設定されます。場合によってはこの2つが一致せず$diffEngineObject->setTextLanguage ($code) を代用します。
- 1.19以降、時刻と数字の書式マジックワードも設定します。DIRECTIONMARKは対象ですが、NAMESPACE(E)は、実際にはサイト言語に依存するので対象外です。言語Bを用いるページにおいて言語Aと指定されたテンプレートがあったとしても、そのページでは言語Bでパースされるということに注意してください。
- SkinTemplate (外装) ではページの文字表示について
- 複数言語を用いた単一ページ
- 理論的には単一のページに複数言語を使うことはサポートされていませんが、単純な
<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+
Code structure
First, you have a Language object in 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 も参照してください。
言語オブジェクト
There are two ways to get a language object.
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.
You can get $languageFactory
, an object of the MediaWiki\Languages\LanguageFactory
class, using Dependency Injection .)
You can also use wfGetLangObj( $code );
if $code
could already be a language object.
The list of codes is in 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.
Old local translation system
With MediaWiki 1.3.0, a new system was set up for localising MediaWiki.
Instead of editing the language file and asking developers to apply the change, users could edit the interface strings directly from their wikis.
This is the system in use as of August 2005.
People can find the message they want to translate in Special:AllMessages and then edit the relevant string in the MediaWiki:
namespace.
Once edited, these changes are live.
There was no more need to request an update, and wait for developers to check and update the file.
The system is great for Wikipedia projects; however a side effect is that the MediaWiki language files shipped with the software are no longer quite up-to-date, and it is harder for developers to keep the files on meta in sync with the real language files.
As the default language files do not provide enough translated material, we face two problems:
- New Wikimedia projects created in a language which has not been updated for a long time, need a total re-translation of the interface.
- Other users of MediaWiki (including Wikimedia projects in the same language) are left with untranslated interfaces.
This is especially unfortunate for the smaller languages which don't have many translators.
This is not such a big issue anymore, because translatewiki.net is advertised prominently and used by almost all translations. Local translations still do happen sometimes but they're strongly discouraged. Local messages mostly have to be deleted, moving the relevant translations to translatewiki.net and leaving on the wiki only the site-specific customisation; there's a huge backlog especially in older projects, this tool helps with cleanup.
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.
What can be localised
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.
- 名前空間 - both core and extensions, plus gender-dependent user namespaces
- 曜日(および略語)
- 月(および略語)
- Bookstores for Special:BookSources
- Skin names
- Math names
- Date preferences -
$datePreferences
- Date formats -
$dateFormats
- Default date format -
$defaultDateFormat
- Date preference migration map - for compatibility with old MediaWiki databases
- Default user option overrides
- 言語名
- 国名(Extension:CLDR 経由)
- 通貨名(Extension:CLDR 経由)
- タイムゾーン
- Character encoding conversion via
iconv
- UpperLowerCase first (needs casemaps for some)[clarification needed]
- UpperLowerCase[clarification needed]
- Uppercase words
- Uppercase word breaks[clarification needed]
- Case folding[clarification needed]
- Strip punctuation for MySQL search (search optimisation)
- Get first character
- Alternate encoding
- Recoding for edit (and then recode input)[clarification needed]
- 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 codezyx
.
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 extension default namespaces page.
Special page aliases
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
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:
- 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.
- 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 date formats
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 開発者 .
注記
- ↑ includes/languages/data/Names.php 参照。
- ↑ そうは言いながら2012年時点で言語コードの変種は未解決。2012年8月28日付Niklas Laxström筆 Language validation in MediaWiki (MediaWikiにおける言語の変種)を参照。
- ↑
These are configured by language in the respective
language/classes/LanguageXx.php
orlanguage/messages/MessagesXx.php
files. - ↑ https://gerrit.wikimedia.org/r/211677
関連項目
- 多言語 MediaWiki
- コードから言語名を読み取るには、コアの機能{{#language:<code>}}が使えます。解説はマジックワードを読んでください。