Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -169,9 +169,16 @@ |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
| 173 | + // Can be either NULL or '', ARGH! |
| 174 | + if ( $object->textbox1 === '' ) { |
| 175 | + $editField = null; |
| 176 | + } else { |
| 177 | + $editField = $object->textbox1; |
| 178 | + } |
| 179 | + |
173 | 180 | if ( $xx !== null && $code !== 'en' ) { |
174 | 181 | // Append translation from the file to edit area, if it's empty. |
175 | | - if ($object->firsttime && $object->textbox1 === '' ) { |
| 182 | + if ($object->firsttime && $editField === null ) { |
176 | 183 | $object->textbox1 = $xx; |
177 | 184 | } |
178 | 185 | } |
— | — | @@ -184,11 +191,12 @@ |
185 | 192 | |
186 | 193 | |
187 | 194 | // Some syntactic checks |
188 | | - $translation = ($object->textbox1 !== '') ? $object->textbox1 : $xx; |
| 195 | + $translation = ($editField !== null ) ? $editField : $xx; |
189 | 196 | if ( $translation !== null ) { |
190 | 197 | $message = new TMessage( $key, $en ); |
| 198 | + // Take the contents from edit field as a translation |
191 | 199 | $message->database = $translation; |
192 | | - $checks = MessageChecks::doChecks( $message, $group->getType() ); |
| 200 | + $checks = MessageChecks::doChecks( $message, $group->getType(), $code ); |
193 | 201 | if ( count($checks) ) { |
194 | 202 | $checkMessages = array(); |
195 | 203 | foreach ( $checks as $checkParams ) { |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -46,8 +46,8 @@ |
47 | 47 | $wgAvailableRights[] = 'translate'; |
48 | 48 | |
49 | 49 | define( 'TRANSLATE_FUZZY', '!!FUZZY!!' ); |
50 | | -define( 'TRANSLATE_INDEXFILE', $dir . 'messageindex.ser' ); |
51 | | -define( 'TRANSLATE_CHECKFILE', $dir . 'messagecheck.ser' ); |
| 50 | +define( 'TRANSLATE_INDEXFILE', $dir . 'data/messageindex.ser' ); |
| 51 | +define( 'TRANSLATE_CHECKFILE', $dir . 'data/messagecheck.ser' ); |
52 | 52 | define( 'TRANSLATE_ALIASFILE', $dir . 'aliases.txt' ); |
53 | 53 | |
54 | 54 | # |
Index: trunk/extensions/Translate/scripts/createMessageIndex.php |
— | — | @@ -33,6 +33,7 @@ |
34 | 34 | checkAndAdd( $g, true ); |
35 | 35 | } |
36 | 36 | |
| 37 | +wfMkdirParents( dirname(TRANSLATE_INDEXFILE) ); |
37 | 38 | file_put_contents( TRANSLATE_INDEXFILE, serialize( $hugearray ) ); |
38 | 39 | |
39 | 40 | function checkAndAdd( $g, $ignore = false ) { |
Index: trunk/extensions/Translate/scripts/createCheckIndex.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * @file |
11 | 11 | */ |
12 | 12 | |
| 13 | +$optionsWithArgs = array('groups' ); |
13 | 14 | require( dirname(__FILE__) . '/cli.inc' ); |
14 | 15 | |
15 | 16 | $codes = Language::getLanguageNames( false ); |
— | — | @@ -20,15 +21,23 @@ |
21 | 22 | $codes = array_keys( $codes ); |
22 | 23 | sort( $codes ); |
23 | 24 | |
| 25 | +if ( isset($options['groups'] ) ) { |
| 26 | + $reqGroups = array_map( 'trim', explode( ',', $options['groups'] ) ); |
| 27 | +} else { |
| 28 | + $reqGroups = false; |
| 29 | +} |
24 | 30 | |
25 | | -$supportedTypes = array('mediawiki'); |
26 | | -$problematic = array(); |
| 31 | +$groups = MessageGroups::singleton()->getGroups(); |
27 | 32 | |
28 | | -$groups = MessageGroups::singleton()->getGroups(); |
29 | 33 | foreach ( $groups as $g ) { |
| 34 | + $id = $g->getId(); |
| 35 | + |
| 36 | + // Skip groups that are not requested |
| 37 | + if ( $reqGroups && !in_array($id, $reqGroups) ) continue; |
| 38 | + |
| 39 | + $problematic = array(); |
30 | 40 | $type = $g->getType(); |
31 | 41 | |
32 | | - $id = $g->getId(); |
33 | 42 | STDOUT( "Working with $id: ", true ); |
34 | 43 | |
35 | 44 | foreach ( $codes as $code ) { |
— | — | @@ -39,9 +48,8 @@ |
40 | 49 | $g->fillCollection( $collection ); |
41 | 50 | $namespace = $g->namespaces[0]; |
42 | 51 | |
43 | | - // Remove untranslated messages from the list |
44 | 52 | foreach ( $collection->keys() as $key ) { |
45 | | - $prob = MessageChecks::doFastChecks( $collection[$key], $type ); |
| 53 | + $prob = MessageChecks::doFastChecks( $collection[$key], $type, $code ); |
46 | 54 | if ( $prob ) { |
47 | 55 | // Print it |
48 | 56 | $nsText = $wgContLang->getNsText( $namespace ); |
— | — | @@ -54,7 +62,9 @@ |
55 | 63 | } |
56 | 64 | |
57 | 65 | } |
| 66 | + |
| 67 | + // Store the results |
| 68 | + $file = TRANSLATE_CHECKFILE . "-$id"; |
| 69 | + wfMkdirParents( dirname($file) ); |
| 70 | + file_put_contents( $file, serialize( $problematic ) ); |
58 | 71 | } |
59 | | - |
60 | | -// Store the results |
61 | | -file_put_contents( TRANSLATE_CHECKFILE, serialize( $problematic ) ); |
Index: trunk/extensions/Translate/TranslateTasks.php |
— | — | @@ -182,7 +182,7 @@ |
183 | 183 | |
184 | 184 | } |
185 | 185 | |
186 | | -class ViewProblematicTask extends ViewMessagesTask { |
| 186 | +class ViewProblematicTask extends ReviewMessagesTask { |
187 | 187 | protected $id = 'problematic'; |
188 | 188 | |
189 | 189 | protected function setProcess() { |
— | — | @@ -195,14 +195,15 @@ |
196 | 196 | } |
197 | 197 | |
198 | 198 | protected function filterNonProblematic() { |
199 | | - // Should never happen, DO WHAT I MEAN |
200 | | - if ( !file_exists(TRANSLATE_CHECKFILE) ) { |
| 199 | + $id = $this->group->getId(); |
| 200 | + $file = TRANSLATE_CHECKFILE . "-$id"; |
| 201 | + if ( !file_exists($file) ) { |
201 | 202 | foreach ($this->collection->keys() as $key ) |
202 | 203 | unset( $this->collection[$key] ); |
203 | 204 | return; |
204 | 205 | } |
205 | 206 | |
206 | | - $problematic = unserialize( file_get_contents( TRANSLATE_CHECKFILE ) ); |
| 207 | + $problematic = unserialize( file_get_contents($file) ); |
207 | 208 | |
208 | 209 | $code = $this->options->getLanguage(); |
209 | 210 | if ( isset($problematic[$code]) ) { |
— | — | @@ -438,11 +439,6 @@ |
439 | 440 | public static function getTasks() { |
440 | 441 | global $wgTranslateTasks; |
441 | 442 | |
442 | | - // Hide problematic task from the list if there is no check file. |
443 | | - if ( !file_exists(TRANSLATE_CHECKFILE) ) { |
444 | | - unset($wgTranslateTasks['problematic']); |
445 | | - } |
446 | | - |
447 | 443 | return array_keys( $wgTranslateTasks ); |
448 | 444 | } |
449 | 445 | |
Index: trunk/extensions/Translate/MessageChecks.php |
— | — | @@ -10,36 +10,55 @@ |
11 | 11 | */ |
12 | 12 | class MessageChecks { |
13 | 13 | |
14 | | - // Fastest first |
15 | | - static $checksForType = array( |
16 | | - 'mediawiki' => array( |
17 | | - array( __CLASS__, 'checkPlural' ), |
18 | | - array( __CLASS__, 'checkParameters' ), |
19 | | - array( __CLASS__, 'checkUnknownParameters' ), |
20 | | - array( __CLASS__, 'checkBalance' ), |
21 | | - array( __CLASS__, 'checkLinks' ), |
22 | | - array( __CLASS__, 'checkXHTML' ), |
23 | | - ), |
24 | | - 'freecol' => array( |
25 | | - array( __CLASS__, 'checkFreeColMissingVars' ), |
26 | | - array( __CLASS__, 'checkFreeColExtraVars' ), |
27 | | - ), |
28 | | - ); |
| 14 | + private function __construct() { |
| 15 | + $file = dirname(__FILE__) . '/check-blacklist.php'; |
| 16 | + $this->blacklist = |
| 17 | + ResourceLoader::loadVariableFromPHPFile( $file, 'checkBlacklist' ); |
29 | 18 | |
| 19 | + // Fastest first |
| 20 | + $this->checksForType = array( |
| 21 | + 'mediawiki' => array( |
| 22 | + array( $this, 'checkPlural' ), |
| 23 | + array( $this, 'checkParameters' ), |
| 24 | + array( $this, 'checkUnknownParameters' ), |
| 25 | + array( $this, 'checkBalance' ), |
| 26 | + array( $this, 'checkLinks' ), |
| 27 | + array( $this, 'checkXHTML' ), |
| 28 | + ), |
| 29 | + 'freecol' => array( |
| 30 | + array( $this, 'checkFreeColMissingVars' ), |
| 31 | + array( $this, 'checkFreeColExtraVars' ), |
| 32 | + ), |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + public static function getInstance() { |
| 37 | + static $obj = null; |
| 38 | + if ( $obj === null ) { |
| 39 | + $obj = new MessageChecks; |
| 40 | + } |
| 41 | + return $obj; |
| 42 | + } |
| 43 | + |
| 44 | + public function getChecks( $type ) { |
| 45 | + if ( !isset($this->checksForType[$type]) ) return array(); |
| 46 | + return $this->checksForType[$type]; |
| 47 | + } |
| 48 | + |
30 | 49 | /** |
31 | 50 | * Entry point which runs all checks. |
32 | 51 | * |
33 | 52 | * @param $message Instance of TMessage. |
34 | 53 | * @return Array of warning messages, html-format. |
35 | 54 | */ |
36 | | - public static function doChecks( TMessage $message, $type ) { |
| 55 | + public static function doChecks( TMessage $message, $type, $code ) { |
37 | 56 | if ( $message->translation === null) return false; |
38 | | - if ( !isset(self::$checksForType[$type])) return false; |
| 57 | + $obj = new MessageChecks; |
39 | 58 | $warnings = array(); |
40 | 59 | |
41 | | - foreach ( self::$checksForType[$type] as $check ) { |
| 60 | + foreach ( $obj->getChecks( $type ) as $check ) { |
42 | 61 | $warning = ''; |
43 | | - if ( call_user_func( $check, $message, &$warning ) ) { |
| 62 | + if ( call_user_func( $check, $message, $code, &$warning ) ) { |
44 | 63 | $warnings[] = $warning; |
45 | 64 | } |
46 | 65 | } |
— | — | @@ -47,12 +66,12 @@ |
48 | 67 | return $warnings; |
49 | 68 | } |
50 | 69 | |
51 | | - public static function doFastChecks( TMessage $message, $type ) { |
| 70 | + public static function doFastChecks( TMessage $message, $type, $code ) { |
52 | 71 | if ( $message->translation === null) return false; |
53 | | - if ( !isset(self::$checksForType[$type])) return false; |
54 | 72 | |
55 | | - foreach ( self::$checksForType[$type] as $check ) { |
56 | | - if ( call_user_func( $check, $message ) ) return true; |
| 73 | + $obj = new MessageChecks; |
| 74 | + foreach ( $obj->getChecks( $type ) as $check ) { |
| 75 | + if ( call_user_func( $check, $message, $code ) ) return true; |
57 | 76 | } |
58 | 77 | |
59 | 78 | return false; |
— | — | @@ -65,7 +84,7 @@ |
66 | 85 | * @param $message Instance of TMessage. |
67 | 86 | * @return Array of unused parameters. |
68 | 87 | */ |
69 | | - protected static function checkParameters( TMessage $message, &$desc = null ) { |
| 88 | + protected function checkParameters( TMessage $message, $code, &$desc = null ) { |
70 | 89 | $variables = array( '\$1', '\$2', '\$3', '\$4', '\$5', '\$6', '\$7', '\$8', '\$9' ); |
71 | 90 | |
72 | 91 | $missing = array(); |
— | — | @@ -91,13 +110,13 @@ |
92 | 111 | return false; |
93 | 112 | } |
94 | 113 | |
95 | | - protected static function checkUnknownParameters( TMessage $message, &$desc = null ) { |
| 114 | + protected function checkUnknownParameters( TMessage $message, $code, &$desc = null ) { |
96 | 115 | $variables = array( '\$1', '\$2', '\$3', '\$4', '\$5', '\$6', '\$7', '\$8', '\$9' ); |
97 | 116 | |
98 | 117 | $missing = array(); |
99 | 118 | $definition = $message->definition; |
100 | 119 | $translation= $message->translation; |
101 | | - if ( strpos( $definition, '$' ) === false ) return false; |
| 120 | + if ( strpos( $translation, '$' ) === false ) return false; |
102 | 121 | |
103 | 122 | for ( $i = 1; $i < 10; $i++ ) { |
104 | 123 | $pattern = '/\$' . $i . '/s'; |
— | — | @@ -125,7 +144,7 @@ |
126 | 145 | * @return Array of unbalanced paranthesis pairs with difference of opening |
127 | 146 | * and closing count as value. |
128 | 147 | */ |
129 | | - protected static function checkBalance( TMessage $message, &$desc = null ) { |
| 148 | + protected function checkBalance( TMessage $message, $code, &$desc = null ) { |
130 | 149 | $translation = preg_replace( '/[^{}[\]()]/u', '', $message->translation ); |
131 | 150 | $counts = array( '{' => 0, '}' => 0, '[' => 0, ']' => 0, '(' => 0, ')' => 0 ); |
132 | 151 | |
— | — | @@ -162,7 +181,7 @@ |
163 | 182 | * @param $message Instance of TMessage. |
164 | 183 | * @return Array of problematic links. |
165 | 184 | */ |
166 | | - protected static function checkLinks( TMessage $message, &$desc = null ) { |
| 185 | + protected function checkLinks( TMessage $message, $code, &$desc = null ) { |
167 | 186 | $translation = $message->translation; |
168 | 187 | if ( strpos( $translation, '[[' ) === false ) return false; |
169 | 188 | |
— | — | @@ -197,7 +216,7 @@ |
198 | 217 | * @return Array of tags in invalid syntax with correction suggestions as |
199 | 218 | * value. |
200 | 219 | */ |
201 | | - protected static function checkXHTML( TMessage $message, &$desc = null ) { |
| 220 | + protected function checkXHTML( TMessage $message, $code, &$desc = null ) { |
202 | 221 | $translation = $message->translation; |
203 | 222 | if ( strpos( $translation, '<' ) === false ) return false; |
204 | 223 | |
— | — | @@ -236,7 +255,11 @@ |
237 | 256 | * @param $message Instance of TMessage. |
238 | 257 | * @return True if plural magic word is missing. |
239 | 258 | */ |
240 | | - protected static function checkPlural( TMessage $message, &$desc = null ) { |
| 259 | + protected function checkPlural( TMessage $message, $code, &$desc = null ) { |
| 260 | + if ( isset($this->blacklist[$code]) |
| 261 | + && in_array( 'plural', $this->blacklist[$code] ) ) |
| 262 | + return false; |
| 263 | + |
241 | 264 | $definition = $message->definition; |
242 | 265 | $translation = $message->translation; |
243 | 266 | if ( stripos( $definition, '{{plural:' ) !== false && |
— | — | @@ -249,11 +272,11 @@ |
250 | 273 | } |
251 | 274 | |
252 | 275 | |
253 | | - protected static function checkFreeColMissingVars( TMessage $message, &$desc = null ) { |
254 | | - if ( !preg_match_all( '/%[^%]%/U', $message->definition, $defVars ) ) { |
| 276 | + protected function checkFreeColMissingVars( TMessage $message, $code, &$desc = null ) { |
| 277 | + if ( !preg_match_all( '/%[^% ]+%/U', $message->definition, $defVars ) ) { |
255 | 278 | return false; |
256 | 279 | } |
257 | | - preg_match_all( '/%[^%]%/U', $message->translation, $transVars ); |
| 280 | + preg_match_all( '/%[^% ]+%/U', $message->translation, $transVars ); |
258 | 281 | |
259 | 282 | $missing = self::compareArrays( $defVars[0], $transVars[0] ); |
260 | 283 | |
— | — | @@ -262,7 +285,6 @@ |
263 | 286 | $desc = array( 'translate-checks-parameters', |
264 | 287 | implode( ', ', $missing ), |
265 | 288 | $wgLang->formatNum($count) ); |
266 | | - var_dump( $desc ); |
267 | 289 | return true; |
268 | 290 | } else { |
269 | 291 | return false; |
— | — | @@ -270,11 +292,11 @@ |
271 | 293 | } |
272 | 294 | |
273 | 295 | |
274 | | - protected static function checkFreeColExtraVars( TMessage $message, &$desc = null ) { |
275 | | - if ( !preg_match_all( '/%[^%]%/U', $message->definition, $defVars ) ) { |
| 296 | + protected function checkFreeColExtraVars( TMessage $message, $code, &$desc = null ) { |
| 297 | + if ( !preg_match_all( '/%[^% ]+%/U', $message->definition, $defVars ) ) { |
276 | 298 | return false; |
277 | 299 | } |
278 | | - preg_match_all( '/%[^%]%/U', $message->translation, $transVars ); |
| 300 | + preg_match_all( '/%[^% ]+%/U', $message->translation, $transVars ); |
279 | 301 | |
280 | 302 | $missing = self::compareArrays( $transVars[0], $defVars[0] ); |
281 | 303 | |
— | — | @@ -283,7 +305,6 @@ |
284 | 306 | $desc = array( 'translate-checks-parameters-unknown', |
285 | 307 | implode( ', ', $missing ), |
286 | 308 | $wgLang->formatNum($count) ); |
287 | | - var_dump( $desc ); |
288 | 309 | return true; |
289 | 310 | } else { |
290 | 311 | return false; |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -283,7 +283,8 @@ |
284 | 284 | |
285 | 285 | public function load( $code ) { |
286 | 286 | $file = $this->getFileLocation( $code ); |
287 | | - $messages = $this->mangler->mangle( |
| 287 | + // Can return null, convert to array |
| 288 | + $messages = (array) $this->mangler->mangle( |
288 | 289 | ResourceLoader::loadVariableFromPHPFile( $file, 'messages' ) ); |
289 | 290 | if ( $this->getId() !== 'core' && $code !== 'en' ) { |
290 | 291 | // For branches, load trunk messages that are not in database |