Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/118064
Change subject: WIP Paragraph by paragraph translation ...................................................................... WIP Paragraph by paragraph translation Change-Id: I600ecc61ca2dc56b43ad7f2b3f4f9ba921fff963 --- M modules/source/ext.cx.source.js M modules/translation/ext.cx.translation.js M modules/translation/styles/ext.cx.translation.less M server/segmentation/languages/en/CXParserEn.js 4 files changed, 53 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/64/118064/1 diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js index 037f545..927b921 100644 --- a/modules/source/ext.cx.source.js +++ b/modules/source/ext.cx.source.js @@ -75,12 +75,13 @@ ContentTranslationSource.prototype.load = function () { this.$content.html( mw.cx.data.segmentedContent ); + mw.hook( 'mw.cx.source.loaded' ).fire(); }; ContentTranslationSource.prototype.listen = function () { mw.hook( 'mw.cx.source.ready' ).add( $.proxy( this.load, this ) ); this.$content.on( 'click', 'p, h1, h2, h3, h4, ul', function () { - mw.hook( 'mw.cx.translation.add' ).fire( this.outerHTML ); + mw.hook( 'mw.cx.translation.add' ).fire( this.id ); } ); }; diff --git a/modules/translation/ext.cx.translation.js b/modules/translation/ext.cx.translation.js index fe497da..8409e50 100644 --- a/modules/translation/ext.cx.translation.js +++ b/modules/translation/ext.cx.translation.js @@ -64,7 +64,7 @@ } $content = $( '<div>' ) - .attr( 'contenteditable', true ) + //.attr( 'contenteditable', true ) .addClass( 'cx-column__content' ) .html( '\n' ); // Make sure that it's visible to the tests @@ -76,20 +76,51 @@ ContentTranslationEditor.prototype.listen = function () { mw.hook( 'mw.cx.translation.add' ).add( $.proxy( this.update, this ) ); - + mw.hook( 'mw.cx.source.loaded' ).add( $.proxy( this.addPlaceholders, this ) ); this.$content.on( 'input', function () { mw.hook( 'mw.cx.translation.change' ).fire(); } ); }; - ContentTranslationEditor.prototype.update = function ( content ) { - this.$content.append( content ); + ContentTranslationEditor.prototype.update = function ( sourceId ) { + var sourceHtml = $( '#' + sourceId ).html(); + $( '#t' + sourceId ).html( sourceHtml ); mw.hook( 'mw.cx.progress' ).fire( 100 ); mw.hook( 'mw.cx.translation.change' ).fire(); }; + ContentTranslationEditor.prototype.addPlaceholders = function () { + this.$content.html( mw.cx.data.segmentedContent ); + this.$content.find( 'p, h1, h2, h3, div, table, figure, ul' ).each( function () { + var $section = $( this ), + sectionId = $section.attr( 'id' ); + $section.css( { + 'min-height': $section.height() + } ); + $section.attr( { + 'id': 't' + sectionId, + 'data-source': sectionId, + 'contenteditable': true + } ); + $section.empty(); + $section.hover( function () { + $( this ) + .addClass( 'add-translation' ) + .html( '+ Add Translation' ); + }, function () { + $( this ).removeClass( 'add-translation' ).empty(); + } ); + $section.click( function () { + $( this ) + .removeClass( 'add-translation' ) + .unbind( 'mouseenter mouseleave click' ); + mw.hook( 'mw.cx.translation.add' ).fire( $( this ).data( 'source' ) ); + } ); + } ); + }; + $.fn.cxTranslation = function ( options ) { return this.each( function () { var $this = $( this ), diff --git a/modules/translation/styles/ext.cx.translation.less b/modules/translation/styles/ext.cx.translation.less index 3419209..9e34acb 100644 --- a/modules/translation/styles/ext.cx.translation.less +++ b/modules/translation/styles/ext.cx.translation.less @@ -3,3 +3,12 @@ .cx-column--translation > [contenteditable] { outline: none; } + +.add-translation { + display: block; + text-align: center; + font-size: 20px; + font-weight: lighter; + color: #AAA; + position: relative; +} \ No newline at end of file diff --git a/server/segmentation/languages/en/CXParserEn.js b/server/segmentation/languages/en/CXParserEn.js index 6918450..b805140 100644 --- a/server/segmentation/languages/en/CXParserEn.js +++ b/server/segmentation/languages/en/CXParserEn.js @@ -87,7 +87,7 @@ this.links[this.segmentCount] = { href: href }; - this.print( ' class="cx-link" data-linkid="' + this.segmentCount+++'"' ); + this.print( ' class="cx-link" data-linkid="' + ( this.segmentCount++ ) + '"' ); }; CXParser.prototype.onopentag = function ( tag ) { @@ -105,8 +105,13 @@ } this.print( ' ' + attrName + '="' + entity( tag.attributes[attrName] ) + '"' ); } + if ( tag.name.match( /[ph1-6]|figure|ul|div/ ) ) { + if ( !tag.attributes.id ) { + this.print( ' id="' + ( this.segmentCount++ ) + '"' ); + } + } this.print( '>' ); - if ( tag.name.match( /[ph1-6]/ ) ) { + if ( tag.name.match( /[ph1-6]|figure|ul|div/ ) ) { this.print( this.startSentence() ); } }; -- To view, visit https://gerrit.wikimedia.org/r/118064 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I600ecc61ca2dc56b43ad7f2b3f4f9ba921fff963 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