Index: trunk/extensions/Translate/js/translationdisplay.js |
— | — | @@ -1,14 +0,0 @@ |
2 | | -$(document).ready( function() { |
3 | | - $(".translationdisplay").hover( |
4 | | - function() { $(this).addClass("translationdisplay-hover"); }, |
5 | | - function() { $(this).removeClass("translationdisplay-hover"); } |
6 | | - ); |
7 | | - $("#tt1").click( function() { |
8 | | - $("#tt1").hide(); |
9 | | - $("#tt2").show(); |
10 | | - }); |
11 | | - $("#tt2").click( function() { |
12 | | - $("#tt2").hide(); |
13 | | - $("#tt1").show(); |
14 | | - }); |
15 | | -}); |
Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -417,21 +417,6 @@ |
418 | 418 | return $text; |
419 | 419 | } |
420 | 420 | |
421 | | - public static function injectTranslationDisplayJs( $parser, &$text, $state ) { |
422 | | - if ( strpos( $text, 'translationdisplay' ) !== false ) { |
423 | | - $output = $parser->getOutput(); |
424 | | - if ( method_exists( $output, 'addModules' ) ) { |
425 | | - $output->addModules( 'translationdisplay' ); |
426 | | - } else { |
427 | | - $file = TranslateUtils::assetPath( 'js/translationdisplay.js' ); |
428 | | - $script = Html::linkedScript( $file ); |
429 | | - // How to make sure jQuery is included?? |
430 | | - //$output->addHeadItem( $script, 'translationdisplay' ); |
431 | | - } |
432 | | - } |
433 | | - return true; |
434 | | - } |
435 | | - |
436 | 421 | public static function translateMessageDocumentationLanguage( &$names, $code ) { |
437 | 422 | global $wgTranslateDocumentationLanguageCode; |
438 | 423 | if ( $wgTranslateDocumentationLanguageCode ) { |
— | — | @@ -450,4 +435,29 @@ |
451 | 436 | } |
452 | 437 | return true; |
453 | 438 | } |
| 439 | + |
| 440 | + public static function displayOnDiff( $de, $out ) { |
| 441 | + $title = $de->getTitle(); |
| 442 | + $handle = new MessageHandle( $title ); |
| 443 | + |
| 444 | + if ( !$handle->exists() ) { |
| 445 | + return true; |
| 446 | + } |
| 447 | + |
| 448 | + $de->loadNewText(); |
| 449 | + $out->setRevisionId( $de->mNewRev->getId() ); |
| 450 | + |
| 451 | + $th = new TranslationHelpers( $title ); |
| 452 | + $th->setEditMode( false ); |
| 453 | + $th->setTranslation( $de->mNewtext ); |
| 454 | + TranslateUtils::injectCSS(); |
| 455 | + |
| 456 | + $boxes = array(); |
| 457 | + $boxes[] = $th->getDocumentationBox(); |
| 458 | + $boxes[] = $th->getDefinitionBox(); |
| 459 | + $boxes[] = $th->getTranslationDisplayBox(); |
| 460 | + $output = Html::rawElement( 'div', array( 'class' => 'mw-sp-translate-edit-fields' ), implode( "\n\n", $boxes ) ); |
| 461 | + $out->addHtml( $output ); |
| 462 | + return false; |
| 463 | + } |
454 | 464 | } |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -89,7 +89,6 @@ |
90 | 90 | $wgHooks['EditPageBeforeEditButtons'][] = 'TranslateEditAddons::buttonHack'; |
91 | 91 | $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields'; |
92 | 92 | $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs'; |
93 | | -$wgHooks['ParserBeforeStrip'][] = 'TranslateEditAddons::injectTranslationDisplayJs'; |
94 | 93 | $wgHooks['LanguageGetTranslatedLanguageNames'][] = 'TranslateEditAddons::translateMessageDocumentationLanguage'; |
95 | 94 | $wgHooks['ArticlePrepareTextForEdit'][] = 'TranslateEditAddons::disablePreSaveTransform'; |
96 | 95 | |
— | — | @@ -109,6 +108,9 @@ |
110 | 109 | // Translation memory updates |
111 | 110 | $wgHooks['ArticleSaveComplete'][] = 'TranslationMemoryUpdater::update'; |
112 | 111 | |
| 112 | +// Translation display related |
| 113 | +$wgHooks['ArticleContentOnDiff'][] = 'TranslateEditAddons::displayOnDiff'; |
| 114 | + |
113 | 115 | // New rights |
114 | 116 | $wgAvailableRights[] = 'translate'; |
115 | 117 | $wgAvailableRights[] = 'translate-import'; |
— | — | @@ -122,6 +124,7 @@ |
123 | 125 | ); |
124 | 126 | $wgResourceModules['translationdisplay'] = array( |
125 | 127 | 'scripts' => 'js/translationdisplay.js', |
| 128 | + 'styles' => 'js/translationdisplay.css', |
126 | 129 | 'localBasePath' => dirname( __FILE__ ), |
127 | 130 | 'remoteExtPath' => 'Translate' |
128 | 131 | ); |
Index: trunk/extensions/Translate/utils/TranslationHelpers.php |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | * suggestion directly into the text area, for example. |
46 | 46 | */ |
47 | 47 | protected $textareaId = 'wpTextbox1'; |
| 48 | + /** |
| 49 | + * Whether to include extra tools to aid translating. |
| 50 | + */ |
| 51 | + protected $editMode = 'true'; |
48 | 52 | |
49 | 53 | /** |
50 | 54 | * @param $title Title Title of a page that holds a translation. |
— | — | @@ -106,7 +110,16 @@ |
107 | 111 | $this->textareaId = $id; |
108 | 112 | } |
109 | 113 | |
| 114 | + |
110 | 115 | /** |
| 116 | + * Enable or disable extra help for editing. |
| 117 | + * @param $mode Boolean |
| 118 | + */ |
| 119 | + public function setEditMode( $mode = true ) { |
| 120 | + $this->editMode = $mode; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
111 | 124 | * Gets the message definition. |
112 | 125 | * @return String |
113 | 126 | */ |
— | — | @@ -178,16 +191,7 @@ |
179 | 192 | */ |
180 | 193 | public function getBoxes( $suggestions = 'sync' ) { |
181 | 194 | // Box filter |
182 | | - $all = array( |
183 | | - 'other-languages' => array( $this, 'getOtherLanguagesBox' ), |
184 | | - 'translation-memory' => array( $this, 'getSuggestionBox' ), |
185 | | - 'translation-diff' => array( $this, 'getPageDiff' ), |
186 | | - 'page-translation' => array( $this, 'getTranslationPageDiff' ), |
187 | | - 'separator' => array( $this, 'getSeparatorBox' ), |
188 | | - 'documenation' => array( $this, 'getDocumentationBox' ), |
189 | | - 'definition' => array( $this, 'getDefinitionBox' ), |
190 | | - 'check' => array( $this, 'getCheckBox' ), |
191 | | - ); |
| 195 | + $all = $this->getBoxNames(); |
192 | 196 | |
193 | 197 | if ( $suggestions === 'async' ) { |
194 | 198 | $all['translation-memory'] = array( $this, 'getLazySuggestionBox' ); |
— | — | @@ -215,6 +219,19 @@ |
216 | 220 | } |
217 | 221 | } |
218 | 222 | |
| 223 | + public function getBoxNames() { |
| 224 | + return array( |
| 225 | + 'other-languages' => array( $this, 'getOtherLanguagesBox' ), |
| 226 | + 'translation-memory' => array( $this, 'getSuggestionBox' ), |
| 227 | + 'translation-diff' => array( $this, 'getPageDiff' ), |
| 228 | + 'page-translation' => array( $this, 'getTranslationPageDiff' ), |
| 229 | + 'separator' => array( $this, 'getSeparatorBox' ), |
| 230 | + 'documentation' => array( $this, 'getDocumentationBox' ), |
| 231 | + 'definition' => array( $this, 'getDefinitionBox' ), |
| 232 | + 'check' => array( $this, 'getCheckBox' ), |
| 233 | + ); |
| 234 | + } |
| 235 | + |
219 | 236 | /** |
220 | 237 | * Returns suggestions from a translation memory. |
221 | 238 | * @return Html snippet which contains the suggestions. |
— | — | @@ -299,7 +316,7 @@ |
300 | 317 | return $result; |
301 | 318 | } |
302 | 319 | |
303 | | - protected function getSuggestionBox( $async = false ) { |
| 320 | + public function getSuggestionBox( $async = false ) { |
304 | 321 | global $wgTranslateTranslationServices; |
305 | 322 | |
306 | 323 | $boxes = array(); |
— | — | @@ -594,7 +611,7 @@ |
595 | 612 | return implode( "$divider\n", $suggestions ); |
596 | 613 | } |
597 | 614 | |
598 | | - protected function getDefinitionBox() { |
| 615 | + public function getDefinitionBox() { |
599 | 616 | $en = $this->getDefinition(); |
600 | 617 | if ( $en === null ) { |
601 | 618 | return null; |
— | — | @@ -631,7 +648,22 @@ |
632 | 649 | return TranslateUtils::fieldset( $label, $msg, $class ); |
633 | 650 | } |
634 | 651 | |
635 | | - protected function getCheckBox() { |
| 652 | + public function getTranslationDisplayBox() { |
| 653 | + $en = $this->getTranslation(); |
| 654 | + if ( $en === null ) { |
| 655 | + return null; |
| 656 | + } |
| 657 | + $label = wfMsg( 'translate-edit-translation' ); |
| 658 | + $class = array( 'class' => 'mw-translate-edit-translation' ); |
| 659 | + $msg = Html::rawElement( 'span', |
| 660 | + array( 'class' => 'mw-translate-edit-translationtext' ), |
| 661 | + TranslateUtils::convertWhiteSpaceToHTML( $en ) |
| 662 | + ); |
| 663 | + |
| 664 | + return TranslateUtils::fieldset( $label, $msg, $class ); |
| 665 | + } |
| 666 | + |
| 667 | + public function getCheckBox() { |
636 | 668 | global $wgTranslateDocumentationLanguageCode; |
637 | 669 | |
638 | 670 | $placeholder = Html::element( 'div', array( 'class' => 'mw-translate-messagechecks' ) ); |
— | — | @@ -680,7 +712,7 @@ |
681 | 713 | ) ); |
682 | 714 | } |
683 | 715 | |
684 | | - protected function getOtherLanguagesBox() { |
| 716 | + public function getOtherLanguagesBox() { |
685 | 717 | global $wgLang; |
686 | 718 | |
687 | 719 | $code = $this->targetLanguage; |
— | — | @@ -746,12 +778,13 @@ |
747 | 779 | |
748 | 780 | $class = 'mw-sp-translate-edit-info'; |
749 | 781 | |
750 | | - if ( $info === null ) { |
| 782 | + if ( $info !== null ) $info .= Html::element( 'hr' ); |
| 783 | + $info .= $this->formatGettextComments(); |
| 784 | + |
| 785 | + if ( strval( $info ) === '' ) { |
751 | 786 | $info = wfMsg( 'translate-edit-no-information' ); |
752 | 787 | $class = 'mw-sp-translate-edit-noinfo'; |
753 | 788 | } |
754 | | - |
755 | | - $info .= $this->formatGettextComments(); |
756 | 789 | $class .= ' mw-sp-translate-message-documentation'; |
757 | 790 | |
758 | 791 | $contents = $wgOut->parse( $info ); |
— | — | @@ -759,7 +792,7 @@ |
760 | 793 | $contents = preg_replace( '~^<([a-z]+)>(.*)</\1>$~us', '\2', $contents ); |
761 | 794 | |
762 | 795 | return TranslateUtils::fieldset( |
763 | | - wfMsgHtml( 'translate-edit-information', $edit , $page ), $contents, array( 'class' => $class ) |
| 796 | + wfMsgHtml( 'translate-edit-information', $edit, $page ), $contents, array( 'class' => $class ) |
764 | 797 | ); |
765 | 798 | |
766 | 799 | } |
— | — | @@ -793,7 +826,7 @@ |
794 | 827 | } |
795 | 828 | } |
796 | 829 | } |
797 | | - return "<hr />$out"; |
| 830 | + return "$out"; |
798 | 831 | } |
799 | 832 | } |
800 | 833 | } |
— | — | @@ -999,15 +1032,18 @@ |
1000 | 1033 | } |
1001 | 1034 | |
1002 | 1035 | public function adder( $source ) { |
1003 | | - $target = self::jQueryPathId( $this->getTextareaId() ); |
1004 | | - $source = self::jQueryPathId( $source ); |
1005 | | - $params = array( |
1006 | | - 'onclick' => "jQuery($target).val(jQuery($source).text()).focus(); return false;", |
1007 | | - 'href' => '#', |
1008 | | - 'title' => wfMsg( 'translate-use-suggestion' ) |
1009 | | - ); |
| 1036 | + if ( !$this->editMode ) { |
| 1037 | + return ''; |
| 1038 | + } |
| 1039 | + $target = self::jQueryPathId( $this->getTextareaId() ); |
| 1040 | + $source = self::jQueryPathId( $source ); |
| 1041 | + $params = array( |
| 1042 | + 'onclick' => "jQuery($target).val(jQuery($source).text()).focus(); return false;", |
| 1043 | + 'href' => '#', |
| 1044 | + 'title' => wfMsg( 'translate-use-suggestion' ) |
| 1045 | + ); |
1010 | 1046 | |
1011 | | - return Html::element( 'a', $params, '↓' ); |
| 1047 | + return Html::element( 'a', $params, '↓' ); |
1012 | 1048 | } |
1013 | 1049 | |
1014 | 1050 | public function wrapInsert( $id, $text ) { |
Index: trunk/extensions/Translate/Translate.i18n.php |
— | — | @@ -72,11 +72,12 @@ |
73 | 73 | |
74 | 74 | 'translate-edit-title' => 'Edit "$1"', |
75 | 75 | 'translate-edit-definition' => 'Message definition', |
| 76 | + 'translate-edit-translation' => 'Translation', |
76 | 77 | 'translate-edit-contribute' => 'contribute', |
77 | 78 | 'translate-edit-no-information' => "''This message has no documentation.'' |
78 | 79 | ''If you know where or how this message is used, you can help other translators by adding documentation to this message.''", |
79 | | - 'translate-edit-information' => 'Information about message "$2" ($1)', |
80 | | - 'translate-edit-in-other-languages' => 'Message "$1" in other languages', |
| 80 | + 'translate-edit-information' => 'Information about message ($1)', |
| 81 | + 'translate-edit-in-other-languages' => 'Message in other languages', |
81 | 82 | 'translate-edit-committed' => 'Current translation in software', |
82 | 83 | 'translate-edit-warnings' => 'Warnings about incomplete translations', |
83 | 84 | 'translate-edit-tmsugs' => 'Suggestions from translation memory', |
— | — | @@ -87,10 +88,6 @@ |
88 | 89 | 'translate-edit-tab-next' => '>>>', |
89 | 90 | 'translate-edit-tab-list' => 'Message list', |
90 | 91 | |
91 | | - 'translate-edit-show-def' => 'Message definition', |
92 | | - 'translate-edit-show-trans' => 'Translation', |
93 | | - 'translate-edit-show-click' => 'Click to switch layout', |
94 | | - |
95 | 92 | 'translate-magic-pagename' => 'Extended MediaWiki translation', |
96 | 93 | 'translate-magic-help' => 'You can translate special pages aliases, magic words and namespace names. |
97 | 94 | |