Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.magic.php |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Internationalization file for the magic words in the Live Translate extension. |
| 6 | + * |
| 7 | + * @file LiveTranslate.i18n.magic.php |
| 8 | + * @ingroup LiveTranslate |
| 9 | + * |
| 10 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 11 | + */ |
| 12 | + |
| 13 | +$magicWords = array(); |
| 14 | + |
| 15 | +/** English (English) |
| 16 | + * @author Jeroen De Dauw |
| 17 | + */ |
| 18 | +$magicWords['en'] = array( |
| 19 | + 'LT_NOTRANSLATIONCONTROL' => array( 0, '__NOTRANSLATIONCONTROL__' ), |
| 20 | + 'LT_SHOWTRANSLATIONCONTROL' => array( 0, '__SHOWTRANSLATIONCONTROL__' ), |
| 21 | +); |
Property changes on: trunk/extensions/LiveTranslate/LiveTranslate.i18n.magic.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 22 | + native |
Index: trunk/extensions/LiveTranslate/LiveTranslate.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | die( 'Not an entry point.' ); |
27 | 27 | } |
28 | 28 | |
29 | | -define( 'LiveTranslate_VERSION', '0.5.1' ); |
| 29 | +define( 'LiveTranslate_VERSION', '0.6 alpha' ); |
30 | 30 | |
31 | 31 | $wgExtensionCredits['other'][] = array( |
32 | 32 | 'path' => __FILE__, |
— | — | @@ -44,6 +44,7 @@ |
45 | 45 | unset( $useExtensionPath ); |
46 | 46 | |
47 | 47 | $wgExtensionMessagesFiles['LiveTranslate'] = $egLiveTranslateIP . '/LiveTranslate.i18n.php'; |
| 48 | +$wgExtensionMessagesFiles['LiveTranslateMagic'] = $egLiveTranslateIP . '/LiveTranslate.i18n.magic.php'; |
48 | 49 | |
49 | 50 | $wgAutoloadClasses['LiveTranslateHooks'] = $egLiveTranslateIP . '/LiveTranslate.hooks.php'; |
50 | 51 | $wgAutoloadClasses['ApiImportTranslationMemories'] = $egLiveTranslateIP . '/api/ApiImportTranslationMemories.php'; |
— | — | @@ -72,6 +73,9 @@ |
73 | 74 | $wgHooks['ArticleViewHeader'][] = 'LiveTranslateHooks::onArticleViewHeader'; |
74 | 75 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'LiveTranslateHooks::onSchemaUpdate'; |
75 | 76 | $wgHooks['ArticleSaveComplete'][] = 'LiveTranslateHooks::onArticleSaveComplete'; |
| 77 | +$wgHooks['LanguageGetMagic'][] = 'LiveTranslateHooks::addMagicWords'; |
| 78 | +$wgHooks['InternalParseBeforeLinks'][] = 'LiveTranslateHooks::stripMagicWords'; |
| 79 | +$wgHooks['OutputPageParserOutput'][] = 'LiveTranslateHooks::onOutputPageParserOutput'; |
76 | 80 | |
77 | 81 | $egLTJSMessages = array( |
78 | 82 | 'livetranslate-button-translate', |
— | — | @@ -103,4 +107,6 @@ |
104 | 108 | define( 'TMT_TMX', 1 ); |
105 | 109 | define( 'TMT_GCSV', 2 ); |
106 | 110 | |
| 111 | +$egLiveTranslateMagicWords = array(); |
| 112 | + |
107 | 113 | require_once 'LiveTranslate_Settings.php'; |
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | */ |
27 | 27 | public static function onArticleViewHeader( Article &$article, &$outputDone, &$useParserCache ) { |
28 | 28 | global $egGoogleApiKey, $egLiveTranslateLanguages; |
29 | | - |
| 29 | + |
30 | 30 | $title = $article->getTitle(); |
31 | 31 | |
32 | 32 | $currentLang = LiveTranslateFunctions::getCurrentLang( $title ); |
— | — | @@ -40,13 +40,20 @@ |
41 | 41 | && $article->exists() |
42 | 42 | && ( count( $egLiveTranslateLanguages ) > 1 || ( count( $egLiveTranslateLanguages ) == 1 && $egLiveTranslateLanguages[0] != $currentLang ) ) ) { |
43 | 43 | |
44 | | - global $egLTNSWithTranslationControl, $egLTUnknownNSShowControl; |
45 | | - $ns = $title->getNamespace(); |
46 | | - |
47 | | - if ( ( array_key_exists( $ns, $egLTNSWithTranslationControl ) && $egLTNSWithTranslationControl[$ns] ) |
48 | | - || ( !array_key_exists( $ns, $egLTNSWithTranslationControl ) && $egLTUnknownNSShowControl ) |
49 | | - ) { |
50 | | - self::displayTranslationControl( $currentLang ); |
| 44 | + global $wgParser; |
| 45 | + $po = $wgParser->getOutput(); |
| 46 | + $magicWords = isset( $po->mLTMagicWords ) ? $po->mLTMagicWords : array(); |
| 47 | + |
| 48 | + if ( !in_array( 'LT_NOTRANSLATIONCONTROL', $magicWords ) ) { |
| 49 | + global $egLTNSWithTranslationControl, $egLTUnknownNSShowControl; |
| 50 | + $ns = $title->getNamespace(); |
| 51 | + |
| 52 | + if ( in_array( 'LT_SHOWTRANSLATIONCONTROL', $magicWords ) |
| 53 | + || ( array_key_exists( $ns, $egLTNSWithTranslationControl ) && $egLTNSWithTranslationControl[$ns] ) |
| 54 | + || ( !array_key_exists( $ns, $egLTNSWithTranslationControl ) && $egLTUnknownNSShowControl ) |
| 55 | + ) { |
| 56 | + self::displayTranslationControl( $currentLang ); |
| 57 | + } |
51 | 58 | } |
52 | 59 | } |
53 | 60 | |
— | — | @@ -291,5 +298,61 @@ |
292 | 299 | |
293 | 300 | return true; |
294 | 301 | } |
| 302 | + |
| 303 | + /** |
| 304 | + * Registers the magic words to show and hide the translation control. |
| 305 | + * |
| 306 | + * TODO: apparently there is some new way of doing this for quite a while, |
| 307 | + * which is not linked in the docs. If someone cares to explain the new stuff, |
| 308 | + * I'll be happy to update this. |
| 309 | + * |
| 310 | + * @since 0.6 |
| 311 | + * |
| 312 | + * @param array &$magicWords |
| 313 | + * @param string $langCode |
| 314 | + * |
| 315 | + * @return true |
| 316 | + */ |
| 317 | + public static function addMagicWords( array &$magicWords, $langCode ) { |
| 318 | + $magicWords['LT_NOTRANSLATIONCONTROL'] = array( 0, '__NOTRANSLATIONCONTROL__' ); |
| 319 | + $magicWords['LT_SHOWTRANSLATIONCONTROL'] =array( 0, '__SHOWTRANSLATIONCONTROL__' ); |
295 | 320 | |
| 321 | + return true; |
| 322 | + } |
| 323 | + |
| 324 | + /** |
| 325 | + * Strips the magic words added by Live Translate from the page text. |
| 326 | + * |
| 327 | + * @since 0.6 |
| 328 | + * |
| 329 | + * @param Parser &$parser |
| 330 | + * @param string &$text |
| 331 | + * |
| 332 | + * @return true |
| 333 | + */ |
| 334 | + public static function stripMagicWords( Parser &$parser, &$text ) { |
| 335 | + global $egLiveTranslateMagicWords; |
| 336 | + |
| 337 | + $mw = MagicWord::get( 'LT_NOTRANSLATIONCONTROL' ); |
| 338 | + if ( $mw->matchAndRemove( $text ) ) { |
| 339 | + $egLiveTranslateMagicWords[] = 'LT_NOTRANSLATIONCONTROL'; |
| 340 | + } |
| 341 | + |
| 342 | + $mw = MagicWord::get( 'LT_SHOWTRANSLATIONCONTROL' ); |
| 343 | + if ( $mw->matchAndRemove( $text ) ) { |
| 344 | + $egLiveTranslateMagicWords[] = 'LT_SHOWTRANSLATIONCONTROL'; |
| 345 | + } |
| 346 | + |
| 347 | + $po = $parser->getOutput(); |
| 348 | + $po->mLTMagicWords = $egLiveTranslateMagicWords; |
| 349 | + |
| 350 | + return true; |
| 351 | + } |
| 352 | + |
| 353 | + public static function onOutputPageParserOutput( $outputpage, $parseroutput ) { |
| 354 | + $magicWords = isset( $parseroutput->mLTMagicWords ) ? $parseroutput->mLTMagicWords : array(); |
| 355 | + |
| 356 | + return true; |
| 357 | + } |
| 358 | + |
296 | 359 | } |
Index: trunk/extensions/LiveTranslate/RELEASE-NOTES |
— | — | @@ -4,6 +4,11 @@ |
5 | 5 | Latest version of the release notes: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/LiveTranslate/RELEASE-NOTES?view=co |
6 | 6 | |
7 | 7 | |
| 8 | +=== Version 0.6 === |
| 9 | +2011-xx-xx |
| 10 | + |
| 11 | +* Added settings to specify per-namespace if the translation control should be shown or not. |
| 12 | + |
8 | 13 | === Version 0.5 === |
9 | 14 | 2011-01-16 |
10 | 15 | |