Help:Extension:Translate/コンポーネント

From mediawiki.org
This page is a translated version of the page Help:Extension:Translate/Components and the translation is 88% complete.

翻訳拡張機能はさまざまな面で拡張が可能です。 翻訳の拡張とは、おそらく新規のファイル形式への対応 (節単位のリンク) あるいは新規のメッセージ群 (節単位のリンク) が最も多用されます。 ときには新しくへのリンクを作るため、メッセージチェックまたはフックからコンテンツ翻訳拡張機能を伸ばす方が便利なこともあります。 場合によっては既存のweb API の利用によってのみ利用できる状況があります。

前述の原理のほか、翻訳拡張機能には重要な原理やクラスが多く備わり、翻訳拡張機能のハッキングの際に利用できます。 このページでは翻訳拡張機能の構成要素をすべてわかりやすく解説します。

拡張可能なプライマリの構成要素

WebAPI

  • APIに関する詳細な解説文書

PHP コード上でのみ利用できるフックやインターフェイスに加え、WebAPI も多くのメッセージ群にアクセスして関連の情報や動作を翻訳できます。 MediaWiki API フレームワークに基づき、json や xmlなど複数の出力形式に対応します。

ファイル形式対応 (FFS)

翻訳拡張機能を使うと、ウィキ形式ではないコンテンツの翻訳に使え、たとえばソフトウェアのUIメッセージを処理するにはファイル形式対応 (FFS) のクラスを使います。 これらのクラスはFFSインターフェイスを実装し、ファイルコンテンツの解析と生成を抽象化します。 FFS クラスはYAML 設定ファイルによりFileBasedMessageGroupクラスに充当されます。

メッセージ群

メッセージ群はメッセージ集をまとめます。 さまざまなタイプがあり、翻訳対象ページ、SVG ファイル、ソフトウェアが発するインタフェースメッセージなど、保存してあるファイル形式もさまざまです。 それぞれのメッセージ集インスタンスには固有の識別子と名称、説明を振ってあります。 In the code message groups are primarily referenced by their identifier, while the MessageGroups class can be used to get the instances for a given id. メッセージ集はまた翻訳プロセス関連の多くの動作をコントロールしており、対訳を認める言語類、メッセージ集ワークフローの状態などです。 通常、これらの挙動はグローバルな既定にフォールバックさせます。

The two primary ways to register message groups to Translate are the TranslatePostInitGroups hook and YAML configuration.

翻訳補助 (ヘルパー機能)

翻訳補助とは小さなモジュールで作業中に翻訳者に必要で役立つ情報を表示します。 ヘルパー機能ごとに翻訳メモリや機械翻訳の訳文の候補、メッセージに関する説明文、あるいはメッセージの定義などの基礎情報 – 翻訳対象のテキストを示します。

翻訳にはさまざまなヘルプ機能のクラスが伴います。 新しいクラスを追加するフックは現状では提供されません。 Each class that extends the TranslationAid class only needs to implement one method called getData. It should return the information in structured format (nested arrays), which is then exposed via ApiQueryTranslationAids WebAPI module. ヘルプ機能のクラスの他、提供するデータを翻訳エディタ類で使えるようにするには、変更が必要です。

翻訳補助の特殊な事例として機械翻訳サービスがあります。 次の見出しをご参照ください。

ウェブサービス

Adding more machine translation services can easily be done by extending the TranslationWebService class. 例を見るにはウェブサービスのサブディレクトリを参照。 次のようなクラスの実装には、特定の基本情報が必要です。

  • サービスの URL
  • 対応する言語ペアの一覧
  • MediaWiki で採用する言語コードと異なる独自のコードを使うかどうか
  • API キーが必要なサービスかどうか

When you have this information, it is straightforward to write the mapCode, doPairs and doRequest methods. You should use the TranslationWebServiceException to signal errors. エラーは自動でログに残して追跡し、サービスがダウンすると自動的に停止して不要なリクエスト送付を予防します。 The suggestions will automatically be displayed in the translation editor via the MachineTranslationAid class and the ApiQueryTranslationAids WebAPI module. See also $wgTranslateTranslationServices to see how those services are registered.

メッセージ チェッカー

翻訳の単純な間違いはパソコンで拾い出し、たとえばカッコのペアの過不足、必要なプレースホルダの欠落の検出などです。 これらのチェック機能は警告を発して翻訳エディタに表示されます(常に更新)。 保存した翻訳内に表示される警告もまた、その訳文を古いとマークします(特殊用語で fuzzy)。 メッセージ集単位でどのチェックを採用するか決まります。

その他の構成要素

メッセージ集

メッセージ集は特定のメッセージグループ一覧にアクセスできるようにします。 特定の言語内の特定の言語群を読み込むために使います。 機能としてページ割と絞り込みができます。

現状の制約として特定のコレクションに属するメッセージ集は同じ名前空間に配置しなければなりません。 これはメッセージを集めたグループを含む集約グループが異なる名前空間に作成されないよう予防します。

以下の短い例ではフィンランド語の翻訳を使って、メッセージ集をどのように使うとcore というグループの対訳を抽出して冒頭の10件をプリントする方法を示します。

$group = MessageGroups::getGroup( 'core' );
$collection = $group->initCollection( 'fi' );
$collection->filter( 'ignored' );
$collection->filter( 'translated', false );
$collection->loadTranslations();
$collection->slice( 0, 10 );
foreach ( $collection->keys() as $mkey => $title ) {
	echo $title->getPrefixedText() . ': ';
	echo $collection[$mkey]->translation() . "\n\n";
}

メッセージ

ユーティリティのクラス

フォントの検索

ビットマップ画像をレンダ処理するとき、それぞれの言語もしくはスクリプトに最適なフォントが必要です。 To solve this problem, the FCFontFinder class was written. It uses the fc-match command of the package fontconfig (so this doesn't work on Windows) to find a suitable font. これを有効に働かせるには、サーバに多くのその他のフォントを積まなければなりません。 返し値はフォントファイルへのパスもしくはフォント名を選択できます。

メッセージ群のキャッシュ

The messages of file-based message groups are stored in CDB files. Each language of each group has its own CDB cache file. The reason for cache files are twofold.

First they provide constant and efficient access to message data avoiding the potentially expensive parsing of files in various places. For example the list of message keys for each group can be loaded efficiently when rebuilding a message index.

The second reason is that the cache files are used together with the translations in the wiki to process external message changes. Having a snapshot of the state of translations in files and wiki (hopefully consistent at that point) allows us to automatically deduct whether something has been changed in the wiki or externally and make intelligent choices, leaving only real conflicts (messages changed both externally and on the wiki since last snapshot) to be resolved by the translation administrator.

メッセージ群のユーティリティ

メッセージの索引

メッセージの索引は既存のメッセージ群のマッピングを逆引き。 It provides efficient answer to the questions is this a known message and what groups does this message belong to. メッセージキーの検索を1件でも複数県でも素早く実行します。 種類の異なるバックエンドが複数実行され、それぞれに一長一短があります。

  • Serialized file is fast to parse, but don't provide random access and is very memory inefficient when the number of keys grow.
  • CDB file takes more disk space, but provides random access and reasonably fast lookups, while loading everything into memory is slower.
  • Database backend provides efficient random access and full load with the expense of little slower individual lookups. It also doesn't need to write to any files avoiding any permission problems.
  • Also memory backend (memcached, apc) is provided, which could be useful alternatives to database backend in multiple server setups to reduce database contention.

メッセージの検索は累積的なリビルドに対応しません。 Thus rebuilding the index gets relatively resource intensive when the number of message groups and message keys increase. Depending on the message group, this might involve parsing files or doing database queries and loading the definitions, which can take a lot of memory. The message index rebuilding is triggered in various places in Translate, and by default it is executed immediately during the request. As it gets slower, it can be delayed via the MediaWiki job queue and run outside of web requests.

メッセージ

メタデータ

Revtag

Stats code

文字列対照/並べ替え

Ttmserver (翻訳メモリ)

Ttmserver is the name of translation memory interface. It supports multiple backends for inserting and querying translation suggestions. The code is located under ttmserver directory.

その他:RC 統合、設定、ツールボックス、ジョブ類

リポジトリの配置

リポジトリのルートに格納したファイルは以下のとおりです。

  • Standard MediaWiki extensions files like Translate.php, translations and some documentation files like hooks.txt and README which includes change notes.
  • Major translate classes like MessageCollection and Message and some misc utilities not yet moved under utils.

コードの大部分はサブディレクトリに格納。 主なパーツには独自のサブディレクトリが伴います。

  • api - WebAPI コード用
  • ffs - ファイル形式をサポートするコード
  • messagegroups - メッセージ群用
  • scripts - コマンドラインの文用
  • tag - ページ翻訳のコード用
  • ttmserver - 翻訳メモリのコード用
  • specials - 特別ページ全て
  • tests - PHP ユニットテスト全般に対応

コードの大部分はユーティリティファイル内。 コード以外のための追加フォルダ:

  • data - その他の種類のデータファイル
  • libs - 同梱のライブラリに依存
  • resources - css、スクリプト、画像全て
  • sql - SQL テーブルの定義全て