Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -117,7 +117,7 @@ |
118 | 118 | /** |
119 | 119 | * Define various web services that provide translation suggestions. |
120 | 120 | * Example for tmserver translation memory from translatetoolkit. |
121 | | - * $wgTranslateTranslationServices['local'] = array( |
| 121 | + * $wgTranslateTranslationServices['tmserver'] = array( |
122 | 122 | * 'server' => 'http://127.0.0.1', |
123 | 123 | * 'port' => 54321, |
124 | 124 | * 'timeout-sync' => 3, |
— | — | @@ -164,6 +164,7 @@ |
165 | 165 | 'view' => 'ViewMessagesTask', |
166 | 166 | 'untranslated' => 'ViewUntranslatedTask', |
167 | 167 | 'optional' => 'ViewOptionalTask', |
| 168 | + 'suggestions' => 'ViewWithSuggestionsTask', |
168 | 169 | // 'untranslatedoptional' => 'ViewUntranslatedOptionalTask', |
169 | 170 | 'review' => 'ReviewMessagesTask', |
170 | 171 | 'reviewall' => 'ReviewAllMessagesTask', |
Index: trunk/extensions/Translate/TranslateTasks.php |
— | — | @@ -170,6 +170,53 @@ |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
| 174 | +class ViewWithSuggestionsTask extends ViewMessagesTask { |
| 175 | + protected $id = 'suggestions'; |
| 176 | + |
| 177 | + protected function preinit() { |
| 178 | + $code = $this->options->getLanguage(); |
| 179 | + global $wgTranslateTranslationServices; |
| 180 | + $config = $wgTranslateTranslationServices['tmserver']; |
| 181 | + $server = $config['server']; |
| 182 | + $port = $config['port']; |
| 183 | + $timeout = $config['timeout-sync']; |
| 184 | + |
| 185 | + $this->collection = $this->group->initCollection( $code ); |
| 186 | + $this->collection->setInfile( $this->group->load( $code ) ); |
| 187 | + $this->collection->filter( 'ignored' ); |
| 188 | + $this->collection->filter( 'optional' ); |
| 189 | + $this->collection->filter( 'translated' ); |
| 190 | + $this->collection->filter( 'fuzzy' ); |
| 191 | + $this->collection->loadTranslations(); |
| 192 | + |
| 193 | + $start = time(); |
| 194 | + |
| 195 | + foreach ( $this->collection->keys() as $key => $_ ) { |
| 196 | + if ( time() - $start > 5 || TranslationHelpers::checkTranslationServiceFailure( 'tmserver' ) ) { |
| 197 | + unset( $this->collection[$key] ); |
| 198 | + continue; |
| 199 | + } |
| 200 | + |
| 201 | + $def = rawurlencode( $this->collection[$key]->definition() ); |
| 202 | + $url = "$server:$port/tmserver/en/$code/unit/$def"; |
| 203 | + $suggestions = Http::get( $url, $timeout ); |
| 204 | + |
| 205 | + if ( $suggestions !== false ) { |
| 206 | + $suggestions = FormatJson::decode( $suggestions, true ); |
| 207 | + foreach ( $suggestions as $s ) { |
| 208 | + // We have a good suggestion, do not filter |
| 209 | + if ( $s['quality'] > 0.80 ) { |
| 210 | + continue 2; |
| 211 | + } |
| 212 | + } |
| 213 | + } else { |
| 214 | + TranslationHelpers::reportTranslationSerficeFailure( 'tmserver' ); |
| 215 | + } |
| 216 | + unset( $this->collection[$key] ); |
| 217 | + } |
| 218 | + } |
| 219 | +} |
| 220 | + |
174 | 221 | class ViewUntranslatedOptionalTask extends ViewOptionalTask { |
175 | 222 | protected $id = 'untranslatedoptional'; |
176 | 223 | |
— | — | @@ -375,7 +422,7 @@ |
376 | 423 | |
377 | 424 | class TranslateTasks { |
378 | 425 | public static function getTasks( $pageTranslation = false ) { |
379 | | - global $wgTranslateTasks; |
| 426 | + global $wgTranslateTasks, $wgTranslateTranslationServices; |
380 | 427 | |
381 | 428 | // Tasks not to be available in page translation |
382 | 429 | $filterTasks = array( |
— | — | @@ -396,6 +443,10 @@ |
397 | 444 | } |
398 | 445 | } |
399 | 446 | |
| 447 | + if ( !isset( $wgTranslateTranslationServices['tmserver'] ) ) { |
| 448 | + unset( $allTasks['suggestions'] ); |
| 449 | + } |
| 450 | + |
400 | 451 | return $allTasks; |
401 | 452 | } |
402 | 453 | |
Index: trunk/extensions/Translate/Translate.i18n.php |
— | — | @@ -21,6 +21,7 @@ |
22 | 22 | 'translate-task-view' => 'View all messages from', |
23 | 23 | 'translate-task-untranslated' => 'View all untranslated messages from', |
24 | 24 | 'translate-task-optional' => 'View optional messages from', |
| 25 | + 'translate-task-suggestions' => 'View messages with suggestions from translation memory', |
25 | 26 | 'translate-task-untranslatedoptional' => 'View untranslated optional messages from', |
26 | 27 | 'translate-task-problematic' => 'View messages that have problems', |
27 | 28 | 'translate-task-review' => 'Review changes to', |