Help:Extension:Translate/Group configuration example/ja

This tutorial is for developers and advanced translation administrators. This tutorial explains how to create new configuration files for software interface message translation, detailing the practical aspects of it. It is to be used together with the group configuration reference manual and the developers of the Translate extension will gladly help you with any questions you have after working through this tutorial.

必須条件

 * Mediawiki をインストール
 * 翻訳拡張機能をインストールして、
 * 拡張機能の設定を構成

このチュートリアルは、Translate 拡張機能 リビジョン r97948 (2011-09-23) に基づいて作成されました.

This tutorial describes the process of enabling translation for some parts of the MyBB project. You can follow similar steps to add other projects/files for translation. Some things are specific to translatewiki.net and you should naturally use what is relevant in your case, instead of following the steps of this tutorial blindly.

手順 1: ソースコードのチェックアウト
を作業ディレクトリとして、MyBB のソースコードをチェックアウトしましょう. この例では、作業ディレクトリを  とします. cd /home/betawiki/projects svn co http://svn.mybboard.net/mybb/branches/1.6-stable mybb

sudo -u betawiki svn co http://svn.mybboard.net/mybb/branches/1.6-stable mybb 次に、メッセージを含むファイル群を見つける必要がありますが、これらはサブディレクトリ  にあります. さらにそのサブディレクトリ  に英語の原文メッセージがあります.

では、 をプロジェクトの最初のローカライズ ファイルとして、ここから開始しましょう.

手順 2: ファイル形式対応
In our MediaWiki installation directory, under  and    we can see the classes for file format support, which are used to map message groups to localisation files of each project. You have to do a bit digging to actually see what kind of formats are supported. So we just decide to try and use FlatPhpFFS class first and see how well it works with our PHP file.

So we have a file to map and we have chosen the FFS class for it. Now we need to write a group configuration. That is a YAML file.

In the index you can find a link to Group configuration. Let's start with the minimal file given as example for the BASIC section. We can go ahead and just replace the example text with our own values. The description accepts all wikitext syntax. One nice trick shown in the original example is that you can make it translatable by using. But then you need to define the default text in the page Mediawiki:Message-key. Note that the namespace ID is added through its constant, see how to use custom namespaces.

We need one more thing: the  section. Again starting from the example provided in the documentation: Hmm,  is the language code, like   by default. For now, we do not want to change the directory structure used by MyBB. Instead we can use a feature designed for this purpose: the code map, which allows us to map language codes of each language to the identifiers used by our project.

その結果、以下のようになります:

Basically this says that for code, the   in above will be  , which is the directory for the English message files. The key  is usually the same as , but without the   prefix.

Good. Now let's save this file somewhere, for example to the same folder where LocalSettings.php is stored, with name. The whole file is: Then we must tell our extension to read that file. Add the following line to : After doing this, follow the instructions at Help:Extension:Translate/Group management to run the  script.

So let's log in, make sure the user has the "translate-manage" right configured properly, and go to Special:ManageMessageGroups.

以下のように表示される場合があります: No valid namespace defined, got NS_MYBB. Backtrace: <...> In this case, reading the documentation carefully, you could have identified the need to add the following line to  to register the new namespace with MediaWiki: In this example 1246 is used, but you can pick any free namespace number you need. For the Translate extension, we recommend you to use the even namespace numbers 1200-1298.

If you now reload the ManageMessageGroups special page, you should see a line which says: MyBB This message group has not been imported previously. MyBB リンクをクリックします. クリックすると、ファイル内にメッセージ一覧が現れます. その結果に問題点がない場合は、「実行」をクリックします.

「実行」をクリックすると、ファイルが処理されて以下のような内容が出力されます: Imported new version of page MyBB:L\x5b'boardstats'\x5d/en. Imported new version of page MyBB:L\x5b'new posts'\x5d/en. Imported new version of page MyBB:L\x5b'no new posts'\x5d/en. ... Cache rebuild. All done! ファイルが非常に大きい場合は、最初に  を実行する必要があります. これは PHP のタイムアウト制限によるもので、ウェブ インターフェイスが一度に取り込めるメッセージ数に上限があるためです. この制限に遭遇した場合は、ページ下部にある、残りのメッセージを取り込むボタンをクリックしてください.

手順 3: 他のファイルの追加
MyBB に、翻訳対象の 2 つめのファイルを追加しましょう. この方法は 2 通りあります:

アプローチ 1: 新しい YAML ファイルの追加
単に、新しい YAML ファイルを追加して新しい名前で保存します. さらにそれを  内から呼び出して、上記のすべての手順を実行します. ファイルは以下のようになります: 上記の例でお分かりのように、この新しいグループには異なる ID を使用しなければなりません.

このアプローチは簡単ですが、翻訳単位が大量にある場合には適用できません (つまり、メッセージ群ごとに対応するファイルが必要です). 値の一部を更新する必要が生じた際、これらのファイルすべてを更新する必要があり、大変です. 幸運なことに別の方法があるため、以下に示します:

アプローチ 2: テンプレート構文
The idea is that we pull common values into a template. Then each group will take missing values from the template and there is no need to repeat them for every group.

Let's get back to MyBB example. Let's say you want to include,   and   in the translatable messages. The YAML file needs to be updated like this: As obvious in the above example,  is defined only once; addition and removal of files is as easy as adding or removing a section in the above file.

Now if you go to the ManageMessageGroups special page, you will see three items like this: MyBB global messages: This message group has not been imported previously. MyBB index page: This message group has not been imported previously. MyBB show thread: This message group has not been imported previously.

If there are a lot of files to be included in your project, it may be a good idea to write a script that generated your YAML file for you. An example can be found in trunk/translatewiki/StatusNet/genStatusNet-plugins.php.

手順 4: 集約群
Adding an aggregate group and defining the message files as its subgroups has two benefits:


 * Less work for translators to select different message groups, in particular for maintenance work. Translators can simply open the aggregate group and translate or update everything that needs updating or translation for all the groups.
 * Statistics can be reported on the aggregate group level, i.e. whole project.

In order to define an aggregate group, you need to add the following section right after the TEMPLATE section and before the definition of individual subgroups: This gets us pretty close, but there is still one step missing. At this point, if you go to Special:Translate, you will see the MyBB parent group (and it in fact works!) but also the subgroups listed as separate groups. :(

This is the way to fix it. Add the following line to your : $wgTranslateGroupStructure['/^out-mybb/'] = array( 'mybb' );

This takes all groups whose id match the given pattern, shows the first group, and hides everything else below that first group. A bit ugly, but it works. This construction only supports two layers, even though aggregate groups can be part of aggregate groups.

If you go to Special:Translate now, you will only see the parent group MyBB listed. Additionally, you will see a link "Show 3 subgroups"; clicking on that will show you the names of subgroups.

Check out the manual for TAGS and other sections we didn't go through in this document.

手順 5: クリーンアップ
translatewiki.net が対応しているプロジェクトの YAML ファイルは、Git の リポジトリにコミットされています.

translatewiki.net では、 の行は実際には   にあります. translatewiki.net 上のサンドボックスウィキには TranslateSetting.php がない、というのがすべてを  に追加した理由です.