Message checkers try to find common mistakes so that translators can fix them quickly. More...
Public Member Functions | |
__construct (MessageGroup $group) | |
Constructs a suitable checker for given message group. | |
setChecks ($checks) | |
Set the tests for this checker. | |
addCheck ($check) | |
Adds one tests for this checker. | |
checkMessage (TMessage $message, $code) | |
Checks one message, returns array of warnings that can be passed to OutputPage::addWikiMsg or similar. | |
checkMessageFast (TMessage $message, $code) | |
Checks one message, returns true if any check matches. | |
Protected Member Functions | |
foldValue ($value) | |
Normalises check keys. | |
filterWarnings ($warningsArray) | |
Filters warnings defined in check-blacklist.php. | |
match ($pattern, $value) | |
Matches check information against blacklist pattern. | |
fixMessageParams ($warnings) | |
Converts the special params to something nice. | |
printfCheck ($messages, $code, array &$warnings) | |
Checks for missing and unknown printf formatting characters in translations. | |
rubyVariableCheck ($messages, $code, array &$warnings) | |
Checks for missing and unknown Ruby variables (%{var}) in translations. | |
pythonInterpolationCheck ($messages, $code, array &$warnings) | |
Checks for missing and unknown python string interpolation operators in translations. | |
braceBalanceCheck ($messages, $code, array &$warnings) | |
Checks if the translation has even number of opening and closing parentheses. | |
parameterCheck ($messages, $code, array &$warnings, $pattern) | |
Checks for missing and unknown printf formatting characters in translations. | |
balancedTagsCheck ($messages, $code, array &$warnings) | |
Static Protected Member Functions | |
static | compareArrays ($defs, $trans) |
Compares two arrays return items that don't exist in the latter. | |
Protected Attributes | |
$checks = array() | |
$group = null | |
Static Private Attributes | |
static | $globalBlacklist = null |
Message checkers try to find common mistakes so that translators can fix them quickly.
To implement your own checks, extend this class and add a method of the following type:
protected function myCheck( $messages, $code, &$warnings ) { foreach ( $messages as $message ) { $key = $message->key(); $translation = $message->translation(); if ( strpos( $translation, 'smelly' ) !== false ) { $warnings[$key][] = array( array( 'badword', 'smelly', $key, $code ), 'translate-checks-badword', // Needs to be defined in i18n file array( 'PARAMS', 'smelly' ), ); } } }
Warnings are of format:
$warnings[$key][] = array( # check idenfitication array( 'printf', $subcheck, $key, $code ), # check warning message 'translate-checks-parameters-unknown', # optional special param list, formatted later with Language::commaList() array( 'PARAMS', $params ), # optional number of params, formatted later with Language::formatNum() array( 'COUNT', count( $params ) ), 'Any other parameters to the message',
Definition at line 47 of file MessageChecks.php.
MessageChecker::__construct | ( | MessageGroup $ | group | ) |
Constructs a suitable checker for given message group.
$group | MessageGroup |
Definition at line 56 of file MessageChecks.php.
MessageChecker::addCheck | ( | $ | check | ) |
Adds one tests for this checker.
callable | $check |
Definition at line 113 of file MessageChecks.php.
MessageChecker::balancedTagsCheck | ( | $ | messages, | |
$ | code, | |||
array &$ | warnings | |||
) | [protected] |
TMessage[] | $messages Iterable list of TMessage objects. | |
string | $code Language code | |
array | $warnings Array where warnings are appended to. |
Definition at line 408 of file MessageChecks.php.
MessageChecker::braceBalanceCheck | ( | $ | messages, | |
$ | code, | |||
array &$ | warnings | |||
) | [protected] |
Checks if the translation has even number of opening and closing parentheses.
{, [ and ( are checked.
TMessage[] | $messages Iterable list of TMessage objects. | |
string | $code Language code | |
array | $warnings Array where warnings are appended to. |
Definition at line 315 of file MessageChecks.php.
MessageChecker::checkMessage | ( | TMessage $ | message, | |
$ | code | |||
) |
Checks one message, returns array of warnings that can be passed to OutputPage::addWikiMsg or similar.
TMessage | $message | |
string | $code Language code |
Definition at line 127 of file MessageChecks.php.
MessageChecker::checkMessageFast | ( | TMessage $ | message, | |
$ | code | |||
) |
Checks one message, returns true if any check matches.
TMessage | $message | |
string | $code Language code |
Definition at line 152 of file MessageChecks.php.
static MessageChecker::compareArrays | ( | $ | defs, | |
$ | trans | |||
) | [static, protected] |
Compares two arrays return items that don't exist in the latter.
array | $defs | |
array | $trans |
Definition at line 262 of file MessageChecks.php.
Referenced by parameterCheck().
MessageChecker::filterWarnings | ( | $ | warningsArray | ) | [protected] |
Filters warnings defined in check-blacklist.php.
array | $warningsArray List of warnings produces by checkMessage(). |
Definition at line 171 of file MessageChecks.php.
Referenced by checkMessage().
MessageChecker::fixMessageParams | ( | $ | warnings | ) | [protected] |
Converts the special params to something nice.
Currently useless, but useful if in the future blacklist can work with parameter level too.
array | $warnings List of warnings |
MWException |
Definition at line 229 of file MessageChecks.php.
Referenced by checkMessage().
MessageChecker::foldValue | ( | $ | value | ) | [protected] |
Normalises check keys.
string | $value check key |
Definition at line 90 of file MessageChecks.php.
Referenced by __construct().
MessageChecker::match | ( | $ | pattern, | |
$ | value | |||
) | [protected] |
Matches check information against blacklist pattern.
string | $pattern | |
string | $value The actual value in the warnings produces by the check |
Definition at line 212 of file MessageChecks.php.
Referenced by filterWarnings().
MessageChecker::parameterCheck | ( | $ | messages, | |
$ | code, | |||
array &$ | warnings, | |||
$ | pattern | |||
) | [protected] |
Checks for missing and unknown printf formatting characters in translations.
TMessage[] | $messages Iterable list of TMessage objects. | |
string | $code Language code | |
array | $warnings Array where warnings are appended to. | |
string | $pattern Regular expression for matching variables. |
Definition at line 366 of file MessageChecks.php.
Referenced by printfCheck(), pythonInterpolationCheck(), rubyVariableCheck(), and MediaWikiMessageChecker::wikiParameterCheck().
MessageChecker::printfCheck | ( | $ | messages, | |
$ | code, | |||
array &$ | warnings | |||
) | [protected] |
Checks for missing and unknown printf formatting characters in translations.
TMessage[] | $messages Iterable list of TMessage objects. | |
string | $code Language code | |
array | $warnings Array where warnings are appended to. |
Definition at line 281 of file MessageChecks.php.
MessageChecker::pythonInterpolationCheck | ( | $ | messages, | |
$ | code, | |||
array &$ | warnings | |||
) | [protected] |
Checks for missing and unknown python string interpolation operators in translations.
TMessage[] | $messages Iterable list of TMessage objects. | |
string | $code Language code | |
array | $warnings Array where warnings are appended to. |
Definition at line 303 of file MessageChecks.php.
MessageChecker::rubyVariableCheck | ( | $ | messages, | |
$ | code, | |||
array &$ | warnings | |||
) | [protected] |
Checks for missing and unknown Ruby variables (%{var}) in translations.
TMessage[] | $messages Iterable list of TMessage objects. | |
string | $code Language code | |
array | $warnings Array where warnings are appended to. |
Definition at line 292 of file MessageChecks.php.
MessageChecker::setChecks | ( | $ | checks | ) |
Set the tests for this checker.
Array of callables with descriptive keys.
array | $checks List of checks (suitable methods in this class) |
Definition at line 98 of file MessageChecks.php.
MessageChecker::$checks = array() [protected] |
Definition at line 48 of file MessageChecks.php.
Referenced by setChecks().
MessageChecker::$globalBlacklist = null [static, private] |
Definition at line 50 of file MessageChecks.php.
MessageChecker::$group = null [protected] |
Definition at line 49 of file MessageChecks.php.