Index: trunk/extensions/Translate/Translate.css |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | padding: 0.5em; |
112 | 112 | } |
113 | 113 | |
114 | | -.mw-tpt-sp-legend { |
| 114 | +.mw-tpt-sp-legend, .mw-translate-manage-legend { |
115 | 115 | font-weight: bold; |
116 | 116 | } |
117 | 117 | |
— | — | @@ -118,10 +118,5 @@ |
119 | 119 | font-size: small; |
120 | 120 | padding-left: 2em; |
121 | 121 | padding-right: 2em; |
122 | | - padding-bottom: 1ex; |
123 | | -} |
124 | | - |
125 | | -.mw-tpt-sp-markform .diff-lineno, .mw-sp-translate-edit-fields .diff-lineno { |
126 | | - /* Ideally there should be no line numbers in the first place */ |
127 | | - display:none; |
128 | | -} |
| 122 | + padding-bottom: 2ex; |
| 123 | +} |
\ No newline at end of file |
Index: trunk/extensions/Translate/scripts/createMessageIndex.php |
— | — | @@ -41,14 +41,18 @@ |
42 | 42 | function checkAndAdd( $g, $ignore = false ) { |
43 | 43 | global $hugearray; |
44 | 44 | |
45 | | - $messages = $g->getDefinitions(); |
| 45 | + if ( $g instanceof MessageGroupBase ) { |
| 46 | + $messages = $g->load( 'en' ); |
| 47 | + } else { |
| 48 | + $messages = $g->getDefinitions(); |
| 49 | + } |
46 | 50 | $id = $g->getId(); |
47 | 51 | |
48 | 52 | if ( !is_array( $messages ) ) continue; |
49 | 53 | |
50 | 54 | STDOUT( "$id ", 'main' ); |
51 | 55 | |
52 | | - $namespace = $g->namespaces[0]; |
| 56 | + $namespace = $g->getNamespace(); |
53 | 57 | |
54 | 58 | foreach ( $messages as $key => $data ) { |
55 | 59 | # Force all keys to lower case, because the case doesn't matter and it is |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -200,13 +200,13 @@ |
201 | 201 | |
202 | 202 | public function setConfiguration( $conf ) {} |
203 | 203 | public function getConfiguration() {} |
204 | | - public function getNamespace() { |
205 | | - return $this->namespaces[0]; |
| 204 | + public function getNamespace() { return $this->namespaces[0]; } |
| 205 | + public function getFFS() { return null; } |
| 206 | + public function getTags( $type = null ) { |
| 207 | + $tags = $this->getBools(); |
| 208 | + if ( !$type ) return $tags; |
| 209 | + return isset($tags[$type]) ? $tags[$type] : array(); |
206 | 210 | } |
207 | | - |
208 | | - public function getFFS() { |
209 | | - return null; |
210 | | - } |
211 | 211 | } |
212 | 212 | |
213 | 213 | class CoreMessageGroup extends MessageGroupOld { |
Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -21,8 +21,17 @@ |
22 | 22 | list( $key, $code, $group) = self::getKeyCodeGroup( $wgTitle ); |
23 | 23 | if ( $group === null ) return true; |
24 | 24 | |
25 | | - $defs = $group->getDefinitions(); |
26 | | - $skip = array_merge( $group->getIgnored(), $group->getOptional() ); |
| 25 | + if ( $group instanceof MessageGroupBase ) { |
| 26 | + $cache = new MessageGroupCache($group); |
| 27 | + if ( !$cache->exists() ) return true; |
| 28 | + $keys = $cache->getKeys(); |
| 29 | + $defs = array(); |
| 30 | + foreach ( $keys as $key ) $defs[$key] = $cache->get( $key ); |
| 31 | + $skip = array_merge( $group->getTags( 'ignored' ), $group->getTags( 'optional' ) ); |
| 32 | + } else { |
| 33 | + $defs = $group->getDefinitions(); |
| 34 | + $skip = array_merge( $group->getIgnored(), $group->getOptional() ); |
| 35 | + } |
27 | 36 | |
28 | 37 | $next = $prev = $def = null; |
29 | 38 | foreach ( array_keys( $defs ) as $tkey ) { |
— | — | @@ -264,7 +273,7 @@ |
265 | 274 | list( $key, $code, $group ) = self::getKeyCodeGroup( $object->mTitle ); |
266 | 275 | if ( $group === null ) return; |
267 | 276 | |
268 | | - list( $nsMain, /* $nsTalk */ ) = $group->namespaces; |
| 277 | + $nsMain = $group->getNamespace(); |
269 | 278 | |
270 | 279 | $en = $group->getMessage( $key, 'en' ); |
271 | 280 | $xx = $group->getMessage( $key, $code ); |
— | — | @@ -357,7 +366,7 @@ |
358 | 367 | $class = 'mw-sp-translate-edit-noinfo'; |
359 | 368 | } |
360 | 369 | |
361 | | - if ( $group->getType() === 'gettext' ) { |
| 370 | + if ( $group instanceof GettextMessageGroup ) { |
362 | 371 | $reader = $group->getReader( 'en' ); |
363 | 372 | if ( $reader ) { |
364 | 373 | $data = $reader->parseFile(); |
— | — | @@ -404,6 +413,7 @@ |
405 | 414 | wfLoadExtensionMessages( 'PageTranslation' ); |
406 | 415 | $diff = new DifferenceEngine; |
407 | 416 | $diff->setText( $oldtext, $newtext ); |
| 417 | + $diff->setReducedLineNumbers(); |
408 | 418 | $boxes[] = $diff->getDiff( wfMsgHtml('tpt-diff-old'), wfMsgHtml('tpt-diff-new') ); |
409 | 419 | $diff->showDiffStyle(); |
410 | 420 | } |
— | — | @@ -498,7 +508,7 @@ |
499 | 509 | list( $key, $code, $group ) = self::getKeyCodeGroup( $title ); |
500 | 510 | |
501 | 511 | // Unknown message, do not handle |
502 | | - if ( !$group ) return true; |
| 512 | + if ( !$group || !$code ) return true; |
503 | 513 | |
504 | 514 | $cache = new ArrayMemoryCache( 'groupstats' ); |
505 | 515 | $cache->clear( $group->getId(), $code ); |
— | — | @@ -509,12 +519,13 @@ |
510 | 520 | // Check for problems, but only if not fuzzy already |
511 | 521 | global $wgTranslateDocumentationLanguageCode; |
512 | 522 | if ( $code !== $wgTranslateDocumentationLanguageCode ) { |
513 | | - $en = $group->getMessage( $key, 'en' ); |
514 | | - $message = new FatMessage( $key, $en ); |
515 | | - // Take the contents from edit field as a translation |
516 | | - $message->setTranslation( $text ); |
517 | 523 | $checker = $group->getChecker(); |
518 | 524 | if ( $checker ) { |
| 525 | + $en = $group->getMessage( $key, 'en' ); |
| 526 | + $message = new FatMessage( $key, $en ); |
| 527 | + // Take the contents from edit field as a translation |
| 528 | + $message->setTranslation( $text ); |
| 529 | + |
519 | 530 | $checks = $checker->checkMessage( $message, $code ); |
520 | 531 | if ( count( $checks ) ) $fuzzy = true; |
521 | 532 | } |
Index: trunk/extensions/Translate/Groups.php |
— | — | @@ -17,6 +17,8 @@ |
18 | 18 | |
19 | 19 | public function initCollection( $code ); |
20 | 20 | public function load( $code ); |
| 21 | + public function getTags( $type = null ); |
| 22 | + public function getMessage( $key, $code ); |
21 | 23 | } |
22 | 24 | |
23 | 25 | abstract class MessageGroupBase implements MessageGroup { |
— | — | @@ -57,7 +59,7 @@ |
58 | 60 | if ( $class === null ) return null; |
59 | 61 | if ( !class_exists($class) ) throw new MWException( "Checker class $class does not exists" ); |
60 | 62 | |
61 | | - $checker = new $class(); |
| 63 | + $checker = new $class($this); |
62 | 64 | $checks = $this->getFromConf( 'CHECKER','checks' ); |
63 | 65 | if ( !is_array($checks) ) throw new MWException( "Checker class $class not supplied with proper checks" ); |
64 | 66 | |
— | — | @@ -78,7 +80,6 @@ |
79 | 81 | } |
80 | 82 | |
81 | 83 | if ( !class_exists($class) ) throw new MWException( "Mangler class $class does not exists" ); |
82 | | - |
83 | 84 | // TODO: branch handling, merge with upper branch keys |
84 | 85 | $class = $this->getFromConf( 'MANGLER','class' ); |
85 | 86 | $this->mangler = new $class(); |
— | — | @@ -98,40 +99,65 @@ |
99 | 100 | return $collection; |
100 | 101 | } |
101 | 102 | |
| 103 | + public function getMessage( $key, $code ) { |
| 104 | + $cache = new MessageGroupCache( $this ); |
| 105 | + if ( $cache->exists($code) ) { |
| 106 | + $msg = $cache->get( $key, $code ); |
| 107 | + if ( $msg === false ) { // Try harder |
| 108 | + $nkey = str_replace( ' ', '_', strtolower( $key ) ); |
| 109 | + $keys = $cache->getKeys($code); |
| 110 | + foreach ( $keys as $k ) { |
| 111 | + if ( $nkey === str_replace( ' ', '_', strtolower( $k ) ) ) { |
| 112 | + return $cache->get($k); |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + return null; |
| 117 | + } else { |
| 118 | + return null; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + public function getTags( $type = null ) { |
| 123 | + if ( !isset($this->conf['TAGS']) ) return array(); |
| 124 | + |
| 125 | + $tags = $this->conf['TAGS']; |
| 126 | + if ( !$type ) return $tags; |
| 127 | + |
| 128 | + if ( isset($tags[$type]) ) return $tags[$type]; |
| 129 | + return array(); |
| 130 | + } |
| 131 | + |
102 | 132 | protected function setTags( MessageCollection $collection ) { |
103 | | - if ( isset($this->conf['TAGS']) ) { |
104 | | - $tags = $this->conf['TAGS']; |
105 | | - if ( !is_array($tags) ) throw new MWException( 'Tags is not an array' ); |
| 133 | + $tags = $this->getTags(); |
106 | 134 | |
107 | | - $cache = new MessageGroupCache( $this->getId() ); |
108 | | - $messageKeys = $cache->getKeys(); |
| 135 | + $cache = new MessageGroupCache( $this->getId() ); |
| 136 | + $messageKeys = $cache->getKeys(); |
109 | 137 | |
110 | | - // Loop trough all tag types |
111 | | - foreach ( $tags as $type => $patterns ) { |
112 | | - $matches = array(); |
| 138 | + // Loop trough all tag types |
| 139 | + foreach ( $tags as $type => $patterns ) { |
| 140 | + $matches = array(); |
113 | 141 | |
114 | | - // Collect exact keys, no point running them trough string matcher |
115 | | - foreach ( $patterns as $index => $pattern ) { |
116 | | - if ( strpos( $pattern, '*' ) === false ) { |
117 | | - $matches[] = $pattern; |
118 | | - unset($patterns[$index]); |
119 | | - } |
| 142 | + // Collect exact keys, no point running them trough string matcher |
| 143 | + foreach ( $patterns as $index => $pattern ) { |
| 144 | + if ( strpos( $pattern, '*' ) === false ) { |
| 145 | + $matches[] = $pattern; |
| 146 | + unset($patterns[$index]); |
120 | 147 | } |
| 148 | + } |
121 | 149 | |
122 | | - if ( count($patterns) ) { |
123 | | - // Rest of the keys contain wildcards |
124 | | - $conf = array( 'patterns' => $patterns ); |
125 | | - $mangler = new StringMatcher( $conf ); |
| 150 | + if ( count($patterns) ) { |
| 151 | + // Rest of the keys contain wildcards |
| 152 | + $mangler = new StringMatcher( '', $patterns ); |
126 | 153 | |
127 | | - // Use mangler to find messages that match |
128 | | - foreach ( $messageKeys as $key ) { |
129 | | - if ( $mangler->match($key) ) $matches[] = $key; |
130 | | - } |
| 154 | + // Use mangler to find messages that match |
| 155 | + foreach ( $messageKeys as $key ) { |
| 156 | + if ( $mangler->match($key) ) $matches[] = $key; |
131 | 157 | } |
| 158 | + } |
132 | 159 | |
133 | | - // Add the combined matches |
134 | | - $collection->setTags( $type, $matches ); |
135 | | - } |
| 160 | + // Add the combined matches |
| 161 | + $collection->setTags( $type, $matches ); |
136 | 162 | } |
137 | 163 | } |
138 | 164 | |