Help:Extension:Translate/Validators/ja

翻訳対象の文字列は、翻訳結果でもそのまま保持されるべきマークアップを含むことがよくあります. マークアップは特殊な文字を多く含むため、タイプするのが低速・困難になる場合があります. Translate 拡張機能は、翻訳者がボタンをクリックすると、現在のカーソル位置にマークアップの一部が挿入されるようにすることができます. さらに、翻訳に特定のマークアップが欠けている場合、Translate 拡張機能は翻訳者に警告するか、または翻訳を拒否できます. これは、エンド ユーザーにメッセージを正しく表示するためには、通常、このようなマークアップが必須だからです.

例えば、"Adapted by %{name} from a work by %{original}" という文字列の中には、 と   という 2 つの挿入可能な文字列が存在します. 翻訳者がこれらを追加して翻訳しないと、ソフトウェアを使用するエンド ユーザーには適切なメッセージが表示されません.

翻訳の検証を支援する目的で、 フレームワークが追加されました. 翻訳されたメッセージに対してバリデーターが実行され、設定に基づいて警告またはエラー メッセージが翻訳者に表示されます. 警告がある翻訳は保存できますが、エラーがある翻訳は保存できません. の権限がある利用者のみが、エラーのある翻訳を保存できます.

バリデーターを設定する際、必須となるマークアップを識別するための正規表現を定義します. バリデーターは挿入可能としてマークすることもでき、その場合はそのマークアップを翻訳に追加するためのボタンが翻訳者に表示されます.

カスタム バリデーターを追加でき、これはより専門的な検証をするために必要となります.

設定
以下はバリデーターの設定の要約です.

上記の例では:


 * 1)   は、カスタム正規表現を受け取って検証を実行できる同梱されているバリデーターです.
 * 2)   はカスタム バリデーター クラスです.
 * 3)   は別の同梱されているバリデーターです.

は配列の書式を使用します. ここで、各配列の項目で使用されているさまざまなパラメーターを見てみましょう.

Pre-provided / Bundled validators
Following is a list of bundled validators,

BraceBalance
ID:

Ensures that the number of open braces / brackets, matches the number of closed braces / brackets in the translation.

For example, the following translations would pass,



whereas, the following would fail,



This validator cannot be marked as insertable.

EscapeCharacter
ID:

The validator ensures that only the specified escape character are present in a translation.

The allowed escape characters can be specified when adding the validator, and can only include,



This validator is not insertable.

GettextNewline
ID:

This works specifically for GetText based message groups.

Ensures that the translation has the same number of newlines as the source message at the beginning and end of the string.

GettextPlural
ID:

This works specifically on GetText based message groups.

Ensures that if the source / definition contains a plural in the format -, the translation must contain it as well. Based on the language this also checks if the translation has the correct number of plural forms. For example, English has two, but Hebrew has four.

InsertableRegex
ID:

A generic reusable validator that can be used to specify custom validations and insertables.

For example, take the following configuration where the validator is marked as insertable and enforced,

Given the following source message - ''Hello $name. My name is $myName. that is being translated, the translation must have the parameters - $name and $myName''. They will also be displayed as insertables to make it easier for translators to use them in the translation. An absence of these parameters will cause an error to be displayed to the translator.

InsertableRubyVariable
ID:

This is a validator that matches ruby variables in the translations. Internally it extends  and uses the following regex -. This validator is insertable.

例:

IosVariable
ID:

An insertable variable validator for Ios. Regex is used from here here. This validator is insertable.

例:

MatchSet
ID:

Ensures that the translation is present in the list of values. Also takes a parameter -  that can be either true (default) or false.

For example the following configuration, the validator will validate the message with key -  and ensure that the values for it can either be ltr or rtl. Note that LTR or RTL will not be valid values, since  is true by default.

MediaWikiLink
ID:

Checks if the translation uses links that are discouraged. Valid links are those that link to Special: pages,  or project pages trough MediaWiki messages like. Also links in the definition are allowed.

MediaWikiPageName
ID:

Ensures that if the source / definition contains a namespace such as  the translations made do not try to translate the namespaces itself.

MediaWikiParameter
ID:

This is a validator that matches wiki parameters in the translations. Internally it extends  and uses the following regex -. This validator is insertable.

例: ,.

MediaWikiPlural
ID:

Ensures that if the source / definition contains a, the translation should also have it. It can also be used as an insertable. Based on the language this also checks if the translation has the correct number of plural forms. 例えば、英語には 2 個、ヘブライ語には 3 個あります.

MediaWikiTimeList
ID:

Provides validations for expiry options and IP block options specified in the MediaWiki core. These are usually in the format,

The validations ensure that the translations have the exact same number of key-value pairs. These validations are run only on messages with keys,


 * 1) protect-expiry-options
 * 2) ipboptions

Newline
ID:

Ensures that the translation has the same number of newlines as the source / definition message at the beginning of the string. This validator is not insertable.

NotEmpty
ID:

Ensures that the translation has some content, and that content is not just whitespace. This validator is not insertable.

NumericalParameter
ID:

This validator matches numerical parameters by using the following regex:. This validator is insertable.

例: ,  etc.

Printf
ID:

This validator checks for missing and unknown printf formatting characters in translations. This validator is insertable.

例: ,  etc.

PythonInterpolation
ID:

This validator matches python string interpolation variables by using the following regex:. This validator is insertable.

例: ,

Replacement
ID:

Checks if a translation is using the  string, and instead suggests the translator to use the string mentioned under. This validator is not insertable.

SmartFormatPlural
ID:

This works specifically on SmartFormat based message groups.

Ensures that if the source / definition contains a plural in the format -, the translation must contain it as well. Based on the language this also checks if the translation has the correct number of plural forms. 例えば、英語には 2 個、ヘブライ語には 4 個あります.

UnicodePlural
ID:

Ensures that if the source / definition contains a plural in the format -, the translation must contain it as well. Based on the language this also checks if the translation has the correct number of plural forms. 例えば、英語には 2 個、ヘブライ語には 3 個あります.

User interface
The user interface has been updated to differentiate between errors and warnings.

During translation, if an error is noticed with the translation, the Save translation button is disabled unless the user who is translating has  permission.

Additionally validation is also done on the server when the user is saving the translation. This will still allow users who have the  permission to save the translation even if it has errors.

Custom validators
Certain complicated validations might still require a custom validator to be written. Custom validators must implement the  interface.

Below is an example of a custom validator,

Also see the following classes,


 * 1)   - https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Translate/+/master/src/Validation/ValidationIssues.php
 * 2)   - https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Translate/+/master/src/Validation/ValidationIssue.php

The add the custom validator in the configuration file,