Index: trunk/extensions/LiveTranslate/LiveTranslate_Settings.php |
— | — | @@ -18,9 +18,6 @@ |
19 | 19 | die( 'Not an entry point.' ); |
20 | 20 | } |
21 | 21 | |
22 | | -# The name of the page on which the special words translations dirctionary is defined. |
23 | | -$egLiveTranslateDirPage = 'Live Translate Dictionary'; |
24 | | - |
25 | 22 | # https://code.google.com/apis/console |
26 | 23 | $egGoogleApiKey = ''; |
27 | 24 | |
— | — | @@ -35,3 +32,7 @@ |
36 | 33 | # Default translation memory type. |
37 | 34 | # TMT_LTF, TMT_TMX, TMT_GCSV |
38 | 35 | $egLiveTranslateTMT = TMT_LTF; |
| 36 | + |
| 37 | +# The name of the page on which the special words translations dirctionary is defined. |
| 38 | +# NOTICE: This is only used for the initial setup. Use Special:LiveTranslate to modify after installation. |
| 39 | +$egLiveTranslateDirPage = 'Live Translate Dictionary'; |
Index: trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php |
— | — | @@ -62,9 +62,14 @@ |
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
66 | | - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
67 | | - $this->handleSubmission(); |
| 66 | + if ( $wgRequest->wasPosted() ) { |
| 67 | + if ( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 68 | + $this->handleSubmission(); |
| 69 | + } |
68 | 70 | } |
| 71 | + else { |
| 72 | + LiveTranslateFunctions::createInitialMemoryIfNeeded(); |
| 73 | + } |
69 | 74 | |
70 | 75 | $tms = $this->getTMConfigItems(); |
71 | 76 | |
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -31,6 +31,8 @@ |
32 | 32 | $currentLang = LiveTranslateFunctions::getCurrentLang( $title ); |
33 | 33 | |
34 | 34 | if ( $title->getFullText() == $egLiveTranslateDirPage ) { |
| 35 | + LiveTranslateFunctions::createInitialMemoryIfNeeded(); |
| 36 | + |
35 | 37 | $parser = new LTLTFParser(); |
36 | 38 | $tm = $parser->parse( $article->getContent() ); |
37 | 39 | $tus = $tm->getTranslationUnits(); |
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php |
— | — | @@ -314,4 +314,36 @@ |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
| 318 | + /** |
| 319 | + * Creates the initial translation memory if there is none yet. |
| 320 | + * |
| 321 | + * @since 0.4 |
| 322 | + */ |
| 323 | + public static function createInitialMemoryIfNeeded() { |
| 324 | + $dbw = wfGetDb( DB_MASTER ); |
| 325 | + |
| 326 | + $res = $dbw->select( |
| 327 | + 'live_translate_memories', |
| 328 | + array( 'memory_id' ), |
| 329 | + array(), |
| 330 | + __METHOD__, |
| 331 | + array( 'LIMIT' => '1' ) |
| 332 | + ); |
| 333 | + |
| 334 | + $hasTms = false; |
| 335 | + |
| 336 | + foreach ( $res as $tm ) { |
| 337 | + $hasTms = true; |
| 338 | + break; |
| 339 | + } |
| 340 | + |
| 341 | + if ( !$hasTms ) { |
| 342 | + global $egLiveTranslateDirPage; |
| 343 | + $dbw->insert( |
| 344 | + 'live_translate_memories', |
| 345 | + array( 'memory_location' => $egLiveTranslateDirPage, 'memory_type' => 0 ) |
| 346 | + ); |
| 347 | + } |
| 348 | + } |
| 349 | + |
318 | 350 | } |
\ No newline at end of file |