r73888 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73887‎ | r73888 | r73889 >
Date:14:10, 28 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Reduce code duplication
Modified paths:
  • /trunk/extensions/Translate/groups/FreeCol/Checker.php (modified) (history)
  • /trunk/extensions/Translate/groups/MediaWiki/Checker.php (modified) (history)
  • /trunk/extensions/Translate/groups/Shapado/Checker.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/FreeCol/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
@@ -22,39 +22,7 @@
2323 * @param $warnings \array Array where warnings are appended to.
2424 */
2525 protected function FreeColVariablesCheck( $messages, $code, &$warnings ) {
26 - foreach ( $messages as $message ) {
27 - $key = $message->key();
28 - $definition = $message->definition();
29 - $translation = $message->translation();
30 -
31 - $varPattern = '%[a-zA-Z_]+%';
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 - }
 26+ return parent::parameterCheck( $messages, $code, $warnings, '/%[a-zA-Z_]+%/' );
5927 }
6028
6129 /**
Index: trunk/extensions/Translate/groups/Shapado/Checker.php
@@ -22,38 +22,6 @@
2323 * @param $warnings \array Array where warnings are appended to.
2424 */
2525 protected function ShapadoVariablesCheck( $messages, $code, &$warnings ) {
26 - foreach ( $messages as $message ) {
27 - $key = $message->key();
28 - $definition = $message->definition();
29 - $translation = $message->translation();
30 -
31 - $varPattern = '%{[a-zA-Z_]+}';
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 - }
 26+ return parent::parameterCheck( $messages, $code, $warnings, '/%{[a-zA-Z_]+}/' );
5927 }
6028 }
Index: trunk/extensions/Translate/groups/MediaWiki/Checker.php
@@ -23,42 +23,7 @@
2424 * @param $warnings \array Array where warnings are appended to.
2525 */
2626 protected function wikiParameterCheck( $messages, $code, &$warnings ) {
27 - // @todo Gives false positive on (some?) languages for which a
28 - // parameter is completely left out. Example:
29 - // http://translatewiki.net/w/i.php?title=MediaWiki:Configure-ext-ext-dependencies/zh-hant&action=edit
30 - foreach ( $messages as $message ) {
31 - $key = $message->key();
32 - $definition = $message->definition();
33 - $translation = $message->translation();
34 -
35 - $varPattern = '\$[1-9]';
36 - preg_match_all( "/$varPattern/U", $definition, $defVars );
37 - preg_match_all( "/$varPattern/U", $translation, $transVars );
38 -
39 - # Check for missing variables in the translation
40 - $subcheck = 'missing';
41 - $params = self::compareArrays( $defVars[0], $transVars[0] );
42 - if ( count( $params ) ) {
43 - $warnings[$key][] = array(
44 - array( 'variable', $subcheck, $key, $code ),
45 - 'translate-checks-parameters',
46 - array( 'PARAMS', $params ),
47 - array( 'COUNT', count( $params ) ),
48 - );
49 - }
50 -
51 - # Check for unknown variables in the translation
52 - $subcheck = 'unknown';
53 - $params = self::compareArrays( $transVars[0], $defVars[0] );
54 - if ( count( $params ) ) {
55 - $warnings[$key][] = array(
56 - array( 'variable', $subcheck, $key, $code ),
57 - 'translate-checks-parameters-unknown',
58 - array( 'PARAMS', $params ),
59 - array( 'COUNT', count( $params ) ),
60 - );
61 - }
62 - }
 27+ return parent::parameterCheck( $messages, $code, $warnings, '/\$[1-9]/' );
6328 }
6429
6530 /**

Status & tagging log