Index: trunk/extensions/Translate/scripts/tm-export.php |
— | — | @@ -1,110 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Script to bootstrap translatetoolkit translation memory |
5 | | - * |
6 | | - * @author Niklas Laxstrom |
7 | | - * @copyright Copyright © 2010-2011, Niklas Laxström |
8 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
9 | | - * @file |
10 | | - */ |
11 | | - |
12 | | -// Standard boilerplate to define $IP |
13 | | -if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { |
14 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
15 | | -} else { |
16 | | - $dir = dirname( __FILE__ ); $IP = "$dir/../../.."; |
17 | | -} |
18 | | -require_once( "$IP/maintenance/Maintenance.php" ); |
19 | | - |
20 | | -/// Script to bootstrap translatetoolkit translation memory |
21 | | -class TMExport extends Maintenance { |
22 | | - public function __construct() { |
23 | | - parent::__construct(); |
24 | | - $this->mDescription = 'Script to export messages for translatetoolkit translation memory'; |
25 | | - } |
26 | | - |
27 | | - public function execute() { |
28 | | - global $wgContLang; |
29 | | - |
30 | | - $dbw = TranslationMemoryUpdater::getDatabaseHandle(); |
31 | | - if ( $dbw === null ) { |
32 | | - $this->error( "Database file not configured" ); |
33 | | - $this->exit(); |
34 | | - } |
35 | | - $dbw->setFlag( DBO_TRX ); // HUGE speed improvement |
36 | | - |
37 | | - $groups = MessageGroups::singleton()->getGroups(); |
38 | | - // TODO: encapsulate list of valid language codes |
39 | | - $languages = Language::getLanguageNames( false ); |
40 | | - unset( $languages['en'] ); |
41 | | - |
42 | | - foreach ( $groups as $id => $group ) { |
43 | | - if ( $group->isMeta() ) { |
44 | | - continue; |
45 | | - } |
46 | | - |
47 | | - $this->output( "Processing: {$group->getLabel()} ", $id ); |
48 | | - $capitalized = MWNamespace::isCapitalized( $group->getNamespace() ); |
49 | | - $ns_text = $wgContLang->getNsText( $group->getNamespace() ); |
50 | | - |
51 | | - $definitions = $group->load( $group->getSourceLanguage() ); |
52 | | - foreach ( $definitions as $key => $definition ) { |
53 | | - // TODO: would be nice to do key normalisation closer to the message groups, to avoid transforming back and forth. |
54 | | - // But how to preserve the original keys... |
55 | | - $key = strtr( $key, ' ', '_' ); |
56 | | - $key = $capitalized ? $wgContLang->ucfirst( $key ) : $key; |
57 | | - |
58 | | - $dbr = wfGetDB( DB_SLAVE ); |
59 | | - $tables = array( 'page', 'revision', 'text' ); |
60 | | - // selectFields to stfu Revision class |
61 | | - $vars = array_merge( Revision::selectTextFields(), array( 'page_title' ), Revision::selectFields() ); |
62 | | - $conds = array( |
63 | | - 'page_latest = rev_id', |
64 | | - 'rev_text_id = old_id', |
65 | | - 'page_namespace' => $group->getNamespace(), |
66 | | - 'page_title ' . $dbr->buildLike( "$key/", $dbr->anyString() ) |
67 | | - ); |
68 | | - |
69 | | - $res = $dbr->select( $tables, $vars, $conds, __METHOD__ ); |
70 | | - // Assure that there is at least one translation |
71 | | - if ( $res->numRows() < 1 ) { |
72 | | - continue; |
73 | | - } |
74 | | - |
75 | | - $insert = array( |
76 | | - 'text' => $definition, |
77 | | - 'context' => "$ns_text:$key", |
78 | | - 'length' => strlen( $definition ), |
79 | | - 'lang' => $group->getSourceLanguage(), |
80 | | - ); |
81 | | - |
82 | | - $source_id = $dbw->selectField( '`sources`', 'sid', $insert, __METHOD__ ); |
83 | | - if ( $source_id === false ) { |
84 | | - $dbw->insert( '`sources`', $insert, __METHOD__ ); |
85 | | - $source_id = $dbw->insertId(); |
86 | | - } |
87 | | - |
88 | | - $this->output( ' ', $id ); |
89 | | - |
90 | | - foreach ( $res as $row ) { |
91 | | - list( , $code ) = TranslateUtils::figureMessage( $row->page_title ); |
92 | | - $revision = new Revision( $row ); |
93 | | - $insert = array( |
94 | | - 'text' => $revision->getText(), |
95 | | - 'lang' => $code, |
96 | | - 'time' => wfTimestamp(), |
97 | | - 'sid' => $source_id ); |
98 | | - // We only do SQlite which doesn't need to know unique indexes |
99 | | - $dbw->replace( '`targets`', null, $insert, __METHOD__ ); |
100 | | - } |
101 | | - $this->output( "{$res->numRows()}", $id ); |
102 | | - |
103 | | - } // each translation> |
104 | | - |
105 | | - $dbw->commit(); |
106 | | - } // each group> |
107 | | - } |
108 | | -} |
109 | | - |
110 | | -$maintClass = 'TMExport'; |
111 | | -require_once( DO_MAINTENANCE ); |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -124,7 +124,6 @@ |
125 | 125 | $wgHooks['SkinTemplateToolboxEnd'][] = 'TranslateToolbox::toolboxAllTranslations'; |
126 | 126 | |
127 | 127 | // Translation memory updates |
128 | | -$wgHooks['Translate:newTranslation'][] = 'TranslationMemoryUpdater::update'; |
129 | 128 | $wgHooks['Translate:newTranslation'][] = 'TranslateHooks::updateTM'; |
130 | 129 | |
131 | 130 | // Translation display related |
— | — | @@ -321,22 +320,11 @@ |
322 | 321 | |
323 | 322 | /** |
324 | 323 | * Define various web services that provide translation suggestions. |
325 | | - * Example for tmserver translation memory from translatetoolkit. |
326 | | - * <pre> |
327 | | - * $wgTranslateTranslationServices['tmserver'] = array( |
328 | | - * 'server' => 'http://127.0.0.1', |
329 | | - * 'port' => 54321, |
330 | | - * 'timeout-sync' => 3, |
331 | | - * 'timeout-async' => 6, |
332 | | - * 'database' => '/path/to/database.sqlite', |
333 | | - * 'type' => 'tmserver', |
334 | | - * ); |
335 | | - * </pre> |
336 | 324 | * |
337 | 325 | * For Apertium, you should get an API key. |
338 | 326 | * @see http://wiki.apertium.org/wiki/Apertium_web_service |
339 | 327 | * |
340 | | - * The translation services are provided with the following information: |
| 328 | + * The machine translation services are provided with the following information: |
341 | 329 | * - server ip address |
342 | 330 | * - versions of MediaWiki and Translate extension |
343 | 331 | * - clients ip address encrypted with $wgProxyKey |
Index: trunk/extensions/Translate/README |
— | — | @@ -30,6 +30,9 @@ |
31 | 31 | https://translatewiki.net/docs/Translate/html/ |
32 | 32 | |
33 | 33 | == Change log == |
| 34 | +* 2012-03-05 |
| 35 | +- Support for tmserver was removed. Translate comes with TTMServer enabled by default. |
| 36 | + To bootstrap it with current translations, run php scripts/ttmserver-export.php. |
34 | 37 | * 2012-02-19 |
35 | 38 | - MediaWiki 1.18 or later is now required. |
36 | 39 | - Group description of translatable pages can be extended by adding content to |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -107,7 +107,6 @@ |
108 | 108 | $wgAutoloadClasses['TranslateYaml'] = "$dir/utils/TranslateYaml.php"; |
109 | 109 | $wgAutoloadClasses['TranslationEditPage'] = "$dir/utils/TranslationEditPage.php"; |
110 | 110 | $wgAutoloadClasses['TranslationHelpers'] = "$dir/utils/TranslationHelpers.php"; |
111 | | -$wgAutoloadClasses['TranslationMemoryUpdater'] = "$dir/utils/TranslationMemoryUpdater.php"; |
112 | 111 | $wgAutoloadClasses['TranslationStats'] = "$dir/utils/TranslationStats.php"; |
113 | 112 | |
114 | 113 | /**@}*/ |
Index: trunk/extensions/Translate/utils/TranslationMemoryUpdater.php |
— | — | @@ -1,122 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Contains classes for updating the local translation memory. |
5 | | - * |
6 | | - * @file |
7 | | - * @author Niklas Laxström |
8 | | - * @copyright Copyright © 2010, Niklas Laxström |
9 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | | - */ |
11 | | - |
12 | | -/** |
13 | | - * Class for updating the tmserver from translate toolkit during runtime. |
14 | | - */ |
15 | | -class TranslationMemoryUpdater { |
16 | | - /** |
17 | | - * Shovels the new translation into translation memory. |
18 | | - * Hook: Translate:newTranslation |
19 | | - * |
20 | | - * @param $handle MessageHandle |
21 | | - * @param $revision |
22 | | - * @param $text string |
23 | | - * @param $user User |
24 | | - * |
25 | | - * @return bool |
26 | | - */ |
27 | | - public static function update( MessageHandle $handle, $revision, $text, User $user ) { |
28 | | - global $wgContLang; |
29 | | - |
30 | | - $dbw = self::getDatabaseHandle(); |
31 | | - // Not in use or misconfigured |
32 | | - if ( $dbw === null ) { |
33 | | - return true; |
34 | | - } |
35 | | - |
36 | | - // Skip definitions to not slow down mass imports etc. |
37 | | - // These will be added when first translation is made |
38 | | - if ( $handle->getCode() === 'en' ) { |
39 | | - return true; |
40 | | - } |
41 | | - |
42 | | - $group = $handle->getGroup(); |
43 | | - $key = $handle->getKey(); |
44 | | - $code = $handle->getCode(); |
45 | | - $ns_text = $wgContLang->getNsText( $group->getNamespace() ); |
46 | | - $definition = $group->getMessage( $key, 'en' ); |
47 | | - if ( !is_string( $definition ) || !strlen( $definition ) ) { |
48 | | - wfDebugLog( 'tmserver', "Unable to get definition for $ns_text:$key/$code" ); |
49 | | - return true; |
50 | | - } |
51 | | - |
52 | | - $tmDefinition = array( |
53 | | - 'text' => $definition, |
54 | | - 'context' => "$ns_text:$key", |
55 | | - 'length' => strlen( $definition ), |
56 | | - 'lang' => 'en' |
57 | | - ); |
58 | | - |
59 | | - // Check that the definition exists, add it if not |
60 | | - $source_id = $dbw->selectField( '`sources`', 'sid', $tmDefinition, __METHOD__ ); |
61 | | - if ( $source_id === false ) { |
62 | | - $dbw->insert( '`sources`', $tmDefinition, __METHOD__ ); |
63 | | - $source_id = $dbw->insertId(); |
64 | | - wfDebugLog( 'tmserver', "Inserted new tm-definition for $ns_text:$key:\n$definition\n----------" ); |
65 | | - } |
66 | | - |
67 | | - $delete = array( |
68 | | - 'sid' => $source_id, |
69 | | - 'lang' => $code, |
70 | | - ); |
71 | | - |
72 | | - $insert = $delete + array( |
73 | | - 'text' => $text, |
74 | | - 'time' => wfTimestamp(), |
75 | | - ); |
76 | | - |
77 | | - // Purge old translations for this message |
78 | | - $dbw->delete( '`targets`', $delete, __METHOD__ ); |
79 | | - // We only do SQlite which does not need to know unique indexes |
80 | | - $dbw->replace( '`targets`', null, $insert, __METHOD__ ); |
81 | | - wfDebugLog( 'tmserver', "Inserted new tm-translation for $ns_text:$key/$code" ); |
82 | | - |
83 | | - return true; |
84 | | - } |
85 | | - |
86 | | - /** |
87 | | - * Return a handle to tmserver database. |
88 | | - * Tmserver uses a sqlite database, which we access trough MediaWiki's |
89 | | - * SQLite database handler. |
90 | | - * @return DatabaseSqlite or null |
91 | | - */ |
92 | | - public static function getDatabaseHandle() { |
93 | | - global $wgTranslateTranslationServices; |
94 | | - |
95 | | - $database = null; |
96 | | - |
97 | | - foreach ( $wgTranslateTranslationServices as $config ) { |
98 | | - if ( $config['type'] === 'tmserver' && isset( $config['database'] ) ) { |
99 | | - $database = $config['database']; |
100 | | - break; |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - if ( $database === null ) return null; |
105 | | - |
106 | | - if ( !is_string( $database ) ) { |
107 | | - wfDebugLog( 'tmserver', 'Database configuration is not a string' ); |
108 | | - return null; |
109 | | - } |
110 | | - |
111 | | - if ( !file_exists( $database ) ) { |
112 | | - wfDebugLog( 'tmserver', 'Database file does not exist' ); |
113 | | - return null; |
114 | | - } |
115 | | - |
116 | | - if ( !is_writable( $database ) ) { |
117 | | - wfDebugLog( 'tmserver', 'Database file is not writable' ); |
118 | | - return null; |
119 | | - } |
120 | | - |
121 | | - return new DatabaseSqliteStandalone( $database ); |
122 | | - } |
123 | | -} |
Index: trunk/extensions/Translate/utils/TranslationHelpers.php |
— | — | @@ -251,86 +251,6 @@ |
252 | 252 | * @param $config |
253 | 253 | * @return string Html snippet which contains the suggestions. |
254 | 254 | */ |
255 | | - protected function getTmBox( $serviceName, $config ) { |
256 | | - $this->mustHaveDefinition(); |
257 | | - self::checkTranslationServiceFailure( $serviceName ); |
258 | | - |
259 | | - // Needed data |
260 | | - $page = $this->handle->getKey(); |
261 | | - $code = $this->handle->getCode(); |
262 | | - if ( !$code ) { |
263 | | - $code = $this->group->getSourceLanguage(); |
264 | | - } |
265 | | - $definition = $this->getDefinition(); |
266 | | - $ns = $this->handle->getTitle()->getNsText(); |
267 | | - |
268 | | - // Fetch suggestions |
269 | | - $server = $config['server']; |
270 | | - $port = $config['port']; |
271 | | - $timeout = $config['timeout']; |
272 | | - $def = rawurlencode( $definition ); |
273 | | - $url = "$server:$port/tmserver/en/$code/unit/$def"; |
274 | | - $suggestions = Http::get( $url, $timeout ); |
275 | | - |
276 | | - $sugFields = array(); |
277 | | - // Parse suggestions, but limit to three (in case there would be more) |
278 | | - $boxes = array(); |
279 | | - |
280 | | - if ( $suggestions === false ) { |
281 | | - // Assume timeout |
282 | | - self::reportTranslationServiceFailure( $serviceName ); |
283 | | - } |
284 | | - $suggestions = FormatJson::decode( $suggestions, true ); |
285 | | - |
286 | | - foreach ( $suggestions as $s ) { |
287 | | - // No use to suggest them what they are currently viewing |
288 | | - if ( $s['context'] === "$ns:$page" ) { |
289 | | - continue; |
290 | | - } |
291 | | - |
292 | | - $accuracy = wfMsgHtml( 'translate-edit-tmmatch' , sprintf( '%.2f', $s['quality'] ) ); |
293 | | - $legend = array( $accuracy => array() ); |
294 | | - |
295 | | - $source_page = Title::newFromText( $s['context'] . "/$code" ); |
296 | | - if ( $source_page ) { |
297 | | - $legend[$accuracy][] = self::ajaxEditLink( $source_page, '•' ); |
298 | | - } |
299 | | - |
300 | | - $text = $this->suggestionField( $s['target'] ); |
301 | | - $params = array( 'class' => 'mw-sp-translate-edit-tmsug', 'title' => $s['source'] ); |
302 | | - |
303 | | - if ( isset( $sugFields[$s['target']] ) ) { |
304 | | - $sugFields[$s['target']][2] = array_merge_recursive( $sugFields[$s['target']][2], $legend ); |
305 | | - } else { |
306 | | - $sugFields[$s['target']] = array( $text, $params, $legend ); |
307 | | - } |
308 | | - } |
309 | | - |
310 | | - foreach ( $sugFields as $field ) { |
311 | | - list( $text, $params, $label ) = $field; |
312 | | - $legend = array(); |
313 | | - |
314 | | - foreach ( $label as $acc => $links ) { |
315 | | - $legend[] = $acc . ' ' . implode( " ", $links ); |
316 | | - } |
317 | | - |
318 | | - $legend = implode( ' | ', $legend ); |
319 | | - $boxes[] = Html::rawElement( 'div', $params, self::legend( $legend ) . $text . self::clear() ) . "\n"; |
320 | | - } |
321 | | - |
322 | | - $boxes = array_slice( $boxes, 0, 3 ); |
323 | | - $result = implode( "\n", $boxes ); |
324 | | - |
325 | | - // Limit to three max |
326 | | - return $result; |
327 | | - } |
328 | | - |
329 | | - /** |
330 | | - * Returns suggestions from a translation memory. |
331 | | - * @param $serviceName |
332 | | - * @param $config |
333 | | - * @return string Html snippet which contains the suggestions. |
334 | | - */ |
335 | 255 | protected function getTTMServerBox( $serviceName, $config ) { |
336 | 256 | $this->mustHaveDefinition(); |
337 | 257 | $this->mustBeTranslation(); |
— | — | @@ -401,9 +321,7 @@ |
402 | 322 | $config['timeout'] = $config['timeout-sync']; |
403 | 323 | } |
404 | 324 | |
405 | | - if ( $config['type'] === 'tmserver' ) { |
406 | | - $boxes[] = $this->getTmBox( $name, $config ); |
407 | | - } elseif ( $config['type'] === 'ttmserver' ) { |
| 325 | + if ( $config['type'] === 'ttmserver' ) { |
408 | 326 | $boxes[] = $this->getTTMServerBox( $name, $config ); |
409 | 327 | } elseif ( $config['type'] === 'microsoft' ) { |
410 | 328 | $boxes[] = $this->getMicrosoftSuggestion( $name, $config ); |