MessageChecker Class Reference
[Message Checkers]

Message checkers try to find common mistakes so that translators can fix them quickly. More...

Inheritance diagram for MessageChecker:
Inheritance graph
[legend]

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

MessageChecker::__construct ( MessageGroup group  ) 

Constructs a suitable checker for given message group.

Parameters:
$group MessageGroup

Definition at line 56 of file MessageChecks.php.

Here is the call graph for this function:


Member Function Documentation

MessageChecker::addCheck ( check  ) 

Adds one tests for this checker.

See also:
setChecks()
Parameters:
callable $check

Definition at line 113 of file MessageChecks.php.

MessageChecker::balancedTagsCheck ( messages,
code,
array &$  warnings 
) [protected]
Parameters:
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.

Parameters:
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.

Parameters:
TMessage $message
string $code Language code
Returns:
array

Definition at line 127 of file MessageChecks.php.

Here is the call graph for this function:

MessageChecker::checkMessageFast ( TMessage message,
code 
)

Checks one message, returns true if any check matches.

Parameters:
TMessage $message
string $code Language code
Returns:
bool True if there is a problem, false otherwise.

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.

Parameters:
array $defs
array $trans
Returns:
array Items of $defs that are not in $trans.

Definition at line 262 of file MessageChecks.php.

Referenced by parameterCheck().

MessageChecker::filterWarnings ( warningsArray  )  [protected]

Filters warnings defined in check-blacklist.php.

Parameters:
array $warningsArray List of warnings produces by checkMessage().
Returns:
array List of filtered warnings.

Definition at line 171 of file MessageChecks.php.

Referenced by checkMessage().

Here is the call graph for this function:

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.

Parameters:
array $warnings List of warnings
Exceptions:
MWException 
Returns:
array List of warning messages with parameters.

Definition at line 229 of file MessageChecks.php.

Referenced by checkMessage().

MessageChecker::foldValue ( value  )  [protected]

Normalises check keys.

Parameters:
string $value check key
Returns:
string Normalised check key

Definition at line 90 of file MessageChecks.php.

Referenced by __construct().

MessageChecker::match ( pattern,
value 
) [protected]

Matches check information against blacklist pattern.

Parameters:
string $pattern
string $value The actual value in the warnings produces by the check
Returns:
bool True of the pattern matches the value.

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.

Parameters:
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().

Here is the call graph for this function:

MessageChecker::printfCheck ( messages,
code,
array &$  warnings 
) [protected]

Checks for missing and unknown printf formatting characters in translations.

Parameters:
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.

Here is the call graph for this function:

MessageChecker::pythonInterpolationCheck ( messages,
code,
array &$  warnings 
) [protected]

Checks for missing and unknown python string interpolation operators in translations.

Parameters:
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.

Here is the call graph for this function:

MessageChecker::rubyVariableCheck ( messages,
code,
array &$  warnings 
) [protected]

Checks for missing and unknown Ruby variables (%{var}) in translations.

Parameters:
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.

Here is the call graph for this function:

MessageChecker::setChecks ( checks  ) 

Set the tests for this checker.

Array of callables with descriptive keys.

Parameters:
array $checks List of checks (suitable methods in this class)

Definition at line 98 of file MessageChecks.php.


Member Data Documentation

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.


The documentation for this class was generated from the following file:
Generated on Tue Oct 29 00:00:48 2013 for MediaWiki Translate Extension by  doxygen 1.6.3