r40701 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40700‎ | r40701 | r40702 >
Date:13:41, 10 September 2008
Author:siebrand
Status:old
Tags:
Comment:
Adding MessageChecks for Voctrain.
Modified paths:
  • /trunk/extensions/Translate/MessageChecks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageChecks.php
@@ -30,6 +30,11 @@
3131 'checkPrintfExtraVars',
3232 'checkBalance',
3333 ),
 34+ 'voctrain' => array(
 35+ 'checkI18nSprintMissingVars',
 36+ 'checkI18nSprintExtraVars',
 37+ 'checkBalance',
 38+ ),
3439 );
3540
3641 private function __construct() {
@@ -397,6 +402,56 @@
398403 }
399404 }
400405
 406+ /**
 407+ * Checks for translations not containing vars %xx that are in the
 408+ * definition.
 409+ *
 410+ * @param $message Instance of TMessage.
 411+ * @return True if namespace has been tampered with.
 412+ */
 413+ protected function checkI18nSprintMissingVars( TMessage $message, $code, &$desc = null ) {
 414+ if ( !preg_match_all( '/%[^% ]+/U', $message->definition, $defVars ) ) {
 415+ return false;
 416+ }
 417+ preg_match_all( '/%[^% ]+/U', $message->translation, $transVars );
 418+
 419+ $missing = self::compareArrays( $defVars[0], $transVars[0] );
 420+
 421+ if ( $count = count($missing) ) {
 422+ global $wgLang;
 423+ $desc = array( 'translate-checks-parameters',
 424+ implode( ', ', $missing ),
 425+ $wgLang->formatNum($count) );
 426+ return true;
 427+ } else {
 428+ return false;
 429+ }
 430+ }
 431+
 432+ /**
 433+ * Checks for translations containing vars %xx that are not in the
 434+ * definition.
 435+ *
 436+ * @param $message Instance of TMessage.
 437+ * @return True if namespace has been tampered with.
 438+ */
 439+ protected function checkI18nSprintExtraVars( TMessage $message, $code, &$desc = null ) {
 440+ preg_match_all( '/%[^% ]+/U', $message->definition, $defVars );
 441+ preg_match_all( '/%[^% ]+/U', $message->translation, $transVars );
 442+
 443+ $missing = self::compareArrays( $transVars[0], $defVars[0] );
 444+
 445+ if ( $count = count($missing) ) {
 446+ global $wgLang;
 447+ $desc = array( 'translate-checks-parameters-unknown',
 448+ implode( ', ', $missing ),
 449+ $wgLang->formatNum($count) );
 450+ return true;
 451+ } else {
 452+ return false;
 453+ }
 454+ }
 455+
401456 protected static function compareArrays( $defs, $trans ) {
402457 $missing = array();
403458 foreach ( $defs as $defVar ) {