User:APatro (WMF)/T204568 - Extend message checker framework

Objectives
Avoid failing builds due to mistakes by translators [ 1]. To achieve this project maintainers can add error conditions that will not allow translators to save translations that have errors.

Sub objectives

 * 1) Add support for raising errors in the system during translation.
 * 2) Disallow saving translations that have errors.
 * 3) Allow administrators and fuzzy bot to override the checks.
 * 4) Allow project maintainers to specify errors and warnings in groups.yaml.
 * 5) Maintain backwards compatibility with older YAML file format treating existing checkers as warnings.
 * 6) Merge insertables and checkers since they are pretty same, $name should be insertable, warn if not used, and usually prevent saving.
 * 7) Reduce amount of custom code that has to be written currently to implement Insertables.

Let's look at how this has been achieved.

Validators
A new validator framework has been added with the intent of replacing the existing  framework. Validators are run on the translation message and based on the configuration, a warning or error message is shown to the translator. Translations with warnings can still be saved, but ones that have error cannot be saved. Only a user with  right can save translations that have errors.

It is possible to add a regex in the configuration when configuring the Validator, and it can also be made an insertable. Hence while declaring a validator, it is possible to make  insertable, warn the translator if not used, and prevent saving.

Adding a custom validators is still possible.

Configuration
Following is a summarized validator configuration,

In the example above,


 * 1)   is a pre-provided Validator that can accept custom regex and run validations.
 * 2)   is a custom validator class.
 * 3)   is another pre-provided Validator that ensures that each open brace / bracket has a corresponding closing brace / bracket.

uses an array format. Lets look at the various parameters being used here in each array item,

Pre-provided Validators
Following is a list of pre-provided validators,

BraceBalance
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,



As expected, this validator cannot be marked as insertable.

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

For example,lets 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. A absence of these parameters will cause an error to be displayed to the translator.

The regex can be modified to meet other criteria.

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

MediaWikiMisc
<>

MediaWikiPlural
Ensures that if the source / definition contains a, the translation should also have it. It can also be used as an insertable.

Custom Validators
Custom validators must implement the  interface. The