jenkins-bot has submitted this change and it was merged.
Change subject: After MT template applied fire a hook for post processing the
section
......................................................................
After MT template applied fire a hook for post processing the section
Most of this processing was out of sequence after we integrated apertium.
Because of this image adaptation and alignment were misbehaving.
Change-Id: Ib4b33638cd9fbdc713eacceb62d41b0ca2a46c05
---
M modules/tools/ext.cx.tools.mt.js
M modules/translation/ext.cx.translation.js
2 files changed, 56 insertions(+), 48 deletions(-)
Approvals:
Amire80: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/tools/ext.cx.tools.mt.js b/modules/tools/ext.cx.tools.mt.js
index e5d8027..fef63b8 100644
--- a/modules/tools/ext.cx.tools.mt.js
+++ b/modules/tools/ext.cx.tools.mt.js
@@ -39,19 +39,22 @@
}
$section = $( this );
- sourceContent = $section[ 0 ].outerHTML;
+ if ( !mw.cx.tools.mt.enabled() ) {
+ mw.hook( 'mw.cx.translation.postMT' ).fire( $section );
+ return;
+ }
+
+ sourceContent = $section[ 0 ].outerHTML;
mw.cx.mt( mw.cx.sourceLanguage, mw.cx.targetLanguage,
sourceContent )
.done( function ( translation ) {
if ( translation ) {
- $section.html( $( translation
).children().html() )
- .adaptLinks(
mw.cx.targetLanguage );
+ $section.html( $( translation
).children().html() );
}
- } ).fail( function () {
- $section.adaptLinks( mw.cx.targetLanguage );
} ).always( function () {
$section.data( 'cx-mt', true );
mw.hook( 'mw.cx.translation.change' ).fire(
$section );
+ mw.hook( 'mw.cx.translation.postMT' ).fire(
$section );
} );
return this;
diff --git a/modules/translation/ext.cx.translation.js
b/modules/translation/ext.cx.translation.js
index 7de1808..4215f43 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -94,8 +94,8 @@
ContentTranslationEditor.prototype.listen = function () {
var cxTranslation = this;
- mw.hook( 'mw.cx.translation.add' ).add( $.proxy( this.update,
this ) );
-
+ mw.hook( 'mw.cx.translation.add' ).add( $.proxy(
this.applyTranslationTemplate, this ) );
+ mw.hook( 'mw.cx.translation.postMT' ).add( $.proxy(
this.postProcessMT, this ) );
mw.hook( 'mw.cx.source.loaded' ).add( function () {
// Delay adding placeholders. If we calculate the
section
// dimensions before all css and screenpainting is done,
@@ -127,52 +127,21 @@
};
/**
- * Update the translation section with the machine translation
- * @param {string} sourceId source section identifier
- * @param {boolean} machineTranslate Whether to do machine translation;
default is false.
+ * Post-process the section after MT is applied
+ * @param {jQuery} $section
*/
- ContentTranslationEditor.prototype.update = function ( sourceId,
machineTranslate ) {
- var $sourceSection, targetSectionId, $section;
+ ContentTranslationEditor.prototype.postProcessMT = function ( $section
) {
+ var $sourceSection;
- if ( machineTranslate === undefined ) {
- machineTranslate = true;
- }
-
- $sourceSection = $( '#' + sourceId );
- targetSectionId = jquerySelectorForId( sourceId, 'cx' );
- $section = $( targetSectionId );
-
- // Replace the placeholder with the source section
- $section.replaceWith( $sourceSection
- .clone()
- .attr( {
- id: 'cx' + sourceId,
- 'data-source': sourceId
- } )
- );
-
- // $section was replaced. Get the updated instance.
- $section = $( targetSectionId );
-
- if ( machineTranslate ) {
- $section.each( function () {
- if ( mw.cx.tools.mt.enabled() ) {
- $section.machineTranslate();
- }
- } );
- }
-
+ // Adapt links
+ $section.adaptLinks( mw.cx.targetLanguage );
+ // Adapt images
$section.find( 'img' ).adaptImage( mw.cx.targetLanguage );
-
+ // Adapt references
+ $sourceSection = $( '#' + $section.data( 'source' ) );
if ( $.fn.adaptReferences ) { // This is an experimental feature
$section.find( '[typeof="mw:Extension/ref"]'
).adaptReferences();
}
-
- // Trigger input event so that the alignment will be correct
- $section.on( 'input', $.debounce( 200, false, function () {
- $( this ).data( 'cx-mt', false );
- mw.hook( 'mw.cx.translation.change' ).fire( $( this ) );
- } ) );
// If the section is editable, initiate an editor.
// Otherwise make it non-editable. Example: templates
@@ -181,6 +150,12 @@
} else {
$section.cxEditor();
}
+
+ // Trigger input event so that the alignment will be correct
+ $section.on( 'input', $.debounce( 200, false, function () {
+ $( this ).data( 'cx-mt', false );
+ mw.hook( 'mw.cx.translation.change' ).fire( $( this ) );
+ } ) );
// Search for text that was selected using the mouse.
// Delay it to run every 250 ms so it won't fire all the time
while typing.
@@ -197,6 +172,36 @@
} );
mw.hook( 'mw.cx.translation.updated' ).fire();
+ };
+
+ /*
+ * Update the translation section with the machine translation template
+ * @param {string} sourceId source section identifier
+ * @param {boolean} machineTranslate Whether machine translation to be
used or not
+ */
+ ContentTranslationEditor.prototype.applyTranslationTemplate = function
( sourceId, machineTranslate ) {
+ var $sourceSection, targetSectionId, $section;
+
+ $sourceSection = $( '#' + sourceId );
+ targetSectionId = jquerySelectorForId( sourceId, 'cx' );
+ $section = $( targetSectionId );
+
+ // Replace the placeholder with the source section
+ $section.replaceWith( $sourceSection
+ .clone()
+ .attr( {
+ id: 'cx' + sourceId,
+ 'data-source': sourceId
+ } )
+ );
+
+ // $section was replaced. Get the updated instance.
+ $section = $( targetSectionId );
+ if ( machineTranslate ) {
+ $section.machineTranslate();
+ } else {
+ this.postProcessMT( $section );
+ }
};
/**
@@ -228,7 +233,7 @@
function sectionClick() {
/*jshint validthis:true */
$( jquerySelectorForId( $( this ).data( 'source' ) )
).removeClass( 'cx-highlight' );
- mw.hook( 'mw.cx.translation.add' ).fire( $( this ).data(
'source' ) );
+ mw.hook( 'mw.cx.translation.add' ).fire( $( this ).data(
'source' ), true );
}
function sectionMouseEnterHandler() {
--
To view, visit https://gerrit.wikimedia.org/r/147377
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib4b33638cd9fbdc713eacceb62d41b0ca2a46c05
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits