Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/119965

Change subject: Section alignment: Define section types and improve mt replace
......................................................................

Section alignment: Define section types and improve mt replace

Borrowed the section types from VE
Improved the auto translation so that it does not destroy html structure

Change-Id: If019593d8389083545731d1183c9980201287b62
---
M modules/translation/ext.cx.translation.js
1 file changed, 41 insertions(+), 6 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/65/119965/1

diff --git a/modules/translation/ext.cx.translation.js 
b/modules/translation/ext.cx.translation.js
index 6f7059c..690c189 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -83,12 +83,18 @@
 
        };
 
+       /**
+        * Updat the translation section with the machine translation
+        * @param {string} sourceId source section identifier
+        */
        ContentTranslationEditor.prototype.update = function ( sourceId ) {
-               $( '#t' + sourceId ).empty();
-
-               $( '#' + sourceId ).find( '.cx-segment' ).each( function () {
-                       $( '#t' + sourceId ).append( mw.cx.data.mt[ $( this 
).data( 'segmentid' ) ] );
+               // Copy the whole section html to translation section.
+               $( '#t' + sourceId ).html( $( '#' + sourceId ).html() );
+               // For every segment, use MT as replacement
+               $( '#t' + sourceId ).find( '.cx-segment' ).each( function () {
+                       $( this ).html( mw.cx.data.mt[ $( this ).data( 
'segmentid' ) ] );
                } );
+               // Trigger input event so that the alignemnt is right.
                $( '#t' + sourceId ).trigger( 'input' );
 
                this.calculateCompletion();
@@ -104,11 +110,40 @@
                mw.hook( 'mw.cx.progress' ).fire( completeness );
        };
 
+       /**
+        * Generate a jquery selector for all sections
+        * @return {string} the section selector string
+        */
+       ContentTranslationEditor.prototype.getSectionSelector = function () {
+               var i, sectionSelector = '',
+                       sectionTypes = [
+                       'div', 'p',
+                       // tables
+                       'table', 'tbody', 'thead', 'tfoot', 'caption', 'th', 
'tr', 'td',
+                       // lists
+                       'ul', 'ol', 'li', 'dl', 'dt', 'dd',
+                       // HTML5 heading content
+                       'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup',
+                       // HTML5 sectioning content
+                       'article', 'aside', 'body', 'nav', 'section', 'footer', 
'header', 'figure',
+                       'figcaption', 'fieldset', 'details', 'blockquote',
+                       // other
+                       'hr', 'button', 'canvas', 'center', 'col', 'colgroup', 
'embed',
+                       'map', 'object', 'pre', 'progress', 'video'
+                ];
+               for ( i = 0; i < sectionTypes.length; i++ ) {
+                       sectionSelector += sectionTypes[ i ] + ',';
+               }
+               // Remove the trailing comma.
+               sectionSelector = sectionSelector.replace( /,+$/, '' );
+               return sectionSelector;
+       };
+
        ContentTranslationEditor.prototype.addPlaceholders = function () {
-               var cxSections = 'p, h1, h2, h3, div, table, figure, ul';
+               var cxSectionSelector = this.getSectionSelector();
 
                this.$content.html( mw.cx.data.segmentedContent );
-               this.$content.find( cxSections ).each( function () {
+               this.$content.find( cxSectionSelector ).each( function () {
                        var $section = $( this ),
                                sourceSectionId = $section.attr( 'id' ),
                                $sourceSection = $( '#' + sourceSectionId );

-- 
To view, visit https://gerrit.wikimedia.org/r/119965
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If019593d8389083545731d1183c9980201287b62
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to