r73285 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73284‎ | r73285 | r73286 >
Date:13:46, 18 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Reducde code duplication and add one more check for FUDforum
Modified paths:
  • /trunk/extensions/Translate/groups/FUDforum/Checker.php (modified) (history)
  • /trunk/extensions/Translate/groups/FUDforum/FUDforum.yaml (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/FUDforum/FUDforum.yaml
@@ -18,6 +18,7 @@
1919 checks:
2020 - FUDforumSyntaxCheck
2121 - FUDforumVariablesCheck
 22+ - FUDforumLongVariablesCheck
2223 - braceBalanceCheck
2324
2425 AUTOLOAD:
Index: trunk/extensions/Translate/groups/FUDforum/Checker.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @author Niklas Laxström
8 - * @copyright Copyright © 2009, Niklas Laxström
 8+ * @copyright Copyright © 2009-2010, Niklas Laxström
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 */
1111
@@ -14,56 +14,15 @@
1515 * @ingroup MessageCheckers
1616 */
1717 class FUDforumMessageChecker extends MessageChecker {
18 - /**
19 - * Checks for missing and unknown variables in translations.
20 - *
21 - * @param $messages \array Iterable list of TMessage objects.
22 - * @param $code \string Language code of the translations.
23 - * @param $warnings \array Array where warnings are appended to.
24 - */
 18+
2519 protected function FUDforumVariablesCheck( $messages, $code, &$warnings ) {
26 - foreach ( $messages as $message ) {
27 - $key = $message->key();
28 - $definition = $message->definition();
29 - $translation = $message->translation();
 20+ return parent::parameterCheck( $messages, $code, $warnings, '/\$[1-9]/' );
 21+ }
3022
31 - $varPattern = '\$[1-9]';
32 - preg_match_all( "/$varPattern/U", $definition, $defVars );
33 - preg_match_all( "/$varPattern/U", $translation, $transVars );
34 -
35 - # Check for missing variables in the translation
36 - $subcheck = 'missing';
37 - $params = self::compareArrays( $defVars[0], $transVars[0] );
38 - if ( count( $params ) ) {
39 - $warnings[$key][] = array(
40 - array( 'variable', $subcheck, $key, $code ),
41 - 'translate-checks-parameters',
42 - array( 'PARAMS', $params ),
43 - array( 'COUNT', count( $params ) ),
44 - );
45 - }
46 -
47 - # Check for unknown variables in the translation
48 - $subcheck = 'unknown';
49 - $params = self::compareArrays( $transVars[0], $defVars[0] );
50 - if ( count( $params ) ) {
51 - $warnings[$key][] = array(
52 - array( 'variable', $subcheck, $key, $code ),
53 - 'translate-checks-parameters-unknown',
54 - array( 'PARAMS', $params ),
55 - array( 'COUNT', count( $params ) ),
56 - );
57 - }
58 - }
 23+ protected function FUDforumLongVariablesCheck( $messages, $code, &$warnings ) {
 24+ return parent::parameterCheck( $messages, $code, $warnings, '/{VAR: [^}]+}/' );
5925 }
6026
61 - /**
62 - * Checks for incorrect syntax in translations.
63 - *
64 - * @param $messages \array Iterable list of TMessage objects.
65 - * @param $code \string Language code of the translations.
66 - * @param $warnings \array Array where warnings are appended to.
67 - */
6827 protected function FUDforumSyntaxCheck( $messages, $code, &$warnings ) {
6928 foreach ( $messages as $message ) {
7029 $key = $message->key();

Status & tagging log