r72982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72981‎ | r72982 | r72983 >
Date:15:52, 14 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Update message checks on the fly, instead of forcing translators to save the message first.
Modified paths:
  • /trunk/extensions/Translate/js/quickedit.js (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationEditPage.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/js/quickedit.js
@@ -21,6 +21,28 @@
2222 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
2323 */
2424
 25+function MessageCheckUpdater( callback ) {
 26+ this.callback = callback;
 27+
 28+ this.act = function() {
 29+ callback();
 30+ delete this.timeoutID;
 31+ },
 32+
 33+ this.setup = function() {
 34+ this.cancel();
 35+ var self = this;
 36+ this.timeoutID = window.setTimeout( self.act, 600 );
 37+ },
 38+
 39+ this.cancel = function() {
 40+ if(typeof this.timeoutID == "number") {
 41+ window.clearTimeout(this.timeoutID);
 42+ delete this.timeoutID;
 43+ }
 44+ }
 45+}
 46+
2547 var dialogwidth = false;
2648
2749 function trlOpenJsEdit( page, group ) {
@@ -61,7 +83,22 @@
6284 return false;
6385 });
6486
65 - form.find( ".mw-translate-edit-area" ).focus();
 87+ var textarea = form.find( ".mw-translate-edit-area" );
 88+ textarea.focus();
 89+ var checks = form.find( ".mw-translate-messagechecks" );
 90+ if ( checks ) {
 91+
 92+ var checker = new MessageCheckUpdater( function() {
 93+ var url = wgScript + "?title=Special:Translate/editpage&suggestions=checks&page=$1&loadgroup=$2";
 94+ url = url.replace( "$1", page ).replace( "$2", group );
 95+ jQuery.post( url, { translation: textarea.val() } , function(mydata) {
 96+ checks.html( mydata );
 97+ });
 98+ });
 99+
 100+ textarea.keyup( function() { checker.setup(); } );
 101+ }
 102+
66103 addAccessKeys( form );
67104 var b = form.find(".mw-translate-save"); b.val( b.val() + " (a)" );
68105 var b = form.find(".mw-translate-next"); b.val( b.val() + " (s)" );
Index: trunk/extensions/Translate/utils/TranslationEditPage.php
@@ -74,6 +74,11 @@
7575 return;
7676 }
7777
 78+ if ( $this->suggestions === 'checks' ) {
 79+ echo $helpers->getBoxes( $this->suggestions );
 80+ return;
 81+ }
 82+
7883 $translation = $helpers->getTranslation();
7984 $short = strpos( $translation, "\n" ) === false && strlen( $translation ) < 200;
8085 $textareaParams = array(
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -193,6 +193,10 @@
194194 $all['translation-memory'] = array( $this, 'getLazySuggestionBox' );
195195 } elseif ( $suggestions === 'only' ) {
196196 return (string) call_user_func( $all['translation-memory'], 'lazy' );
 197+ } elseif( $suggestions === 'checks' ) {
 198+ global $wgRequest;
 199+ $this->translation = $wgRequest->getText( 'translation' );
 200+ return (string) call_user_func( $all['check'] );
197201 }
198202
199203 $boxes = array();
@@ -546,6 +550,8 @@
547551 protected function getCheckBox() {
548552 global $wgTranslateDocumentationLanguageCode;
549553
 554+ $placeholder = Html::element( 'div', array( 'class' => 'mw-translate-messagechecks' ) );
 555+
550556 if ( $this->group === null ) {
551557 return;
552558 }
@@ -556,7 +562,7 @@
557563 $en = $this->getDefinition();
558564
559565 if ( strval( $translation ) === '' ) {
560 - return null;
 566+ return $placeholder;
561567 }
562568
563569 if ( $code === $wgTranslateDocumentationLanguageCode ) {
@@ -574,7 +580,7 @@
575581
576582 $checks = $checker->checkMessage( $message, $code );
577583 if ( !count( $checks ) ) {
578 - return null;
 584+ return $placeholder;
579585 }
580586
581587 $checkMessages = array();
@@ -583,10 +589,11 @@
584590 $checkMessages[] = call_user_func_array( 'wfMsgExt', $checkParams );
585591 }
586592
587 - return TranslateUtils::fieldset(
 593+ return Html::rawElement( 'div', array( 'class' => 'mw-translate-messagechecks' ),
 594+ TranslateUtils::fieldset(
588595 wfMsgHtml( 'translate-edit-warnings' ), implode( '<hr />', $checkMessages ),
589596 array( 'class' => 'mw-sp-translate-edit-warnings' )
590 - );
 597+ ) );
591598 }
592599
593600 protected function getOtherLanguagesBox() {

Status & tagging log