http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72982
Revision: 72982
Author: nikerabbit
Date: 2010-09-14 15:52:48 +0000 (Tue, 14 Sep 2010)
Log Message:
-----------
Update message checks on the fly, instead of forcing translators to save the
message first.
Modified Paths:
--------------
trunk/extensions/Translate/js/quickedit.js
trunk/extensions/Translate/utils/TranslationEditPage.php
trunk/extensions/Translate/utils/TranslationHelpers.php
Modified: trunk/extensions/Translate/js/quickedit.js
===================================================================
--- trunk/extensions/Translate/js/quickedit.js 2010-09-14 15:49:32 UTC (rev
72981)
+++ trunk/extensions/Translate/js/quickedit.js 2010-09-14 15:52:48 UTC (rev
72982)
@@ -21,6 +21,28 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
*/
+function MessageCheckUpdater( callback ) {
+ this.callback = callback;
+
+ this.act = function() {
+ callback();
+ delete this.timeoutID;
+ },
+
+ this.setup = function() {
+ this.cancel();
+ var self = this;
+ this.timeoutID = window.setTimeout( self.act, 600 );
+ },
+
+ this.cancel = function() {
+ if(typeof this.timeoutID == "number") {
+ window.clearTimeout(this.timeoutID);
+ delete this.timeoutID;
+ }
+ }
+}
+
var dialogwidth = false;
function trlOpenJsEdit( page, group ) {
@@ -61,7 +83,22 @@
return false;
});
- form.find( ".mw-translate-edit-area" ).focus();
+ var textarea = form.find( ".mw-translate-edit-area" );
+ textarea.focus();
+ var checks = form.find( ".mw-translate-messagechecks" );
+ if ( checks ) {
+
+ var checker = new MessageCheckUpdater( function() {
+ var url = wgScript +
"?title=Special:Translate/editpage&suggestions=checks&page=$1&loadgroup=$2";
+ url = url.replace( "$1", page ).replace( "$2",
group );
+ jQuery.post( url, { translation: textarea.val()
} , function(mydata) {
+ checks.html( mydata );
+ });
+ });
+
+ textarea.keyup( function() { checker.setup(); } );
+ }
+
addAccessKeys( form );
var b = form.find(".mw-translate-save"); b.val( b.val() + "
(a)" );
var b = form.find(".mw-translate-next"); b.val( b.val() + "
(s)" );
Modified: trunk/extensions/Translate/utils/TranslationEditPage.php
===================================================================
--- trunk/extensions/Translate/utils/TranslationEditPage.php 2010-09-14
15:49:32 UTC (rev 72981)
+++ trunk/extensions/Translate/utils/TranslationEditPage.php 2010-09-14
15:52:48 UTC (rev 72982)
@@ -74,6 +74,11 @@
return;
}
+ if ( $this->suggestions === 'checks' ) {
+ echo $helpers->getBoxes( $this->suggestions );
+ return;
+ }
+
$translation = $helpers->getTranslation();
$short = strpos( $translation, "\n" ) === false && strlen(
$translation ) < 200;
$textareaParams = array(
Modified: trunk/extensions/Translate/utils/TranslationHelpers.php
===================================================================
--- trunk/extensions/Translate/utils/TranslationHelpers.php 2010-09-14
15:49:32 UTC (rev 72981)
+++ trunk/extensions/Translate/utils/TranslationHelpers.php 2010-09-14
15:52:48 UTC (rev 72982)
@@ -193,6 +193,10 @@
$all['translation-memory'] = array( $this,
'getLazySuggestionBox' );
} elseif ( $suggestions === 'only' ) {
return (string) call_user_func(
$all['translation-memory'], 'lazy' );
+ } elseif( $suggestions === 'checks' ) {
+ global $wgRequest;
+ $this->translation = $wgRequest->getText( 'translation'
);
+ return (string) call_user_func( $all['check'] );
}
$boxes = array();
@@ -546,6 +550,8 @@
protected function getCheckBox() {
global $wgTranslateDocumentationLanguageCode;
+ $placeholder = Html::element( 'div', array( 'class' =>
'mw-translate-messagechecks' ) );
+
if ( $this->group === null ) {
return;
}
@@ -556,7 +562,7 @@
$en = $this->getDefinition();
if ( strval( $translation ) === '' ) {
- return null;
+ return $placeholder;
}
if ( $code === $wgTranslateDocumentationLanguageCode ) {
@@ -574,7 +580,7 @@
$checks = $checker->checkMessage( $message, $code );
if ( !count( $checks ) ) {
- return null;
+ return $placeholder;
}
$checkMessages = array();
@@ -583,10 +589,11 @@
$checkMessages[] = call_user_func_array( 'wfMsgExt',
$checkParams );
}
- return TranslateUtils::fieldset(
+ return Html::rawElement( 'div', array( 'class' =>
'mw-translate-messagechecks' ),
+ TranslateUtils::fieldset(
wfMsgHtml( 'translate-edit-warnings' ), implode( '<hr
/>', $checkMessages ),
array( 'class' => 'mw-sp-translate-edit-warnings' )
- );
+ ) );
}
protected function getOtherLanguagesBox() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs