[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Clarify section Id and section number difference
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/384933 ) Change subject: CX2: Clarify section Id and section number difference .. CX2: Clarify section Id and section number difference Section Id is sectionIdPrefix+ Section number Also, make sure section number is incremented unconditionally. This will help restoring sections from a saved translation when a new section from source article get support at later point. Otherwise that newly supported section in source will cause all section number order go wrong. Change-Id: I9b91f759d2aecf0aceae00c84a30fb9deabee1d7 --- M modules/dm/mw.cx.dm.Translation.js 1 file changed, 8 insertions(+), 7 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index b3a5025..01ddd9b 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -70,7 +70,7 @@ */ mw.cx.dm.Translation.static.getSourceDom = function ( sourceHtml, forTarget, savedTranslationUnits ) { var lastAboutGroup, - nextSectionId = 1, + sectionNumber = 0, sectionIdPrefix = forTarget ? 'cxTargetSection' : 'cxSourceSection', domDoc = ve.init.target.parseDocument( sourceHtml, 'visual' ), articleNode = domDoc.createElement( 'article' ), @@ -89,10 +89,12 @@ // Wrap each top-level element with a // TODO: it would be better to do section wrapping on the CX server Array.prototype.forEach.call( domDoc.body.childNodes, function ( node ) { - var sectionNode, aboutGroup; - if ( forTarget && savedTranslationUnits && savedTranslationUnits[ nextSectionId ] ) { - sectionNode = this.getSavedTranslation( savedTranslationUnits[ nextSectionId ] ); - nextSectionId++; + var sectionNode, aboutGroup, sectionId; + + sectionNumber++; + sectionId = sectionIdPrefix + sectionNumber; + if ( forTarget && savedTranslationUnits && savedTranslationUnits[ sectionNumber ] ) { + sectionNode = this.getSavedTranslation( savedTranslationUnits[ sectionNumber ] ); } else { if ( node.nodeType !== Node.ELEMENT_NODE ) { return; @@ -103,9 +105,8 @@ // For about-grouped siblings of block level templates don't give them // a section ID if ( !aboutGroup || aboutGroup !== lastAboutGroup ) { - sectionNode.setAttribute( 'id', sectionIdPrefix + nextSectionId ); + sectionNode.setAttribute( 'id', sectionId ); sectionNode.setAttribute( 'rel', forTarget ? 'cx:Placeholder' : 'cx:Section' ); - nextSectionId++; } lastAboutGroup = aboutGroup; -- To view, visit https://gerrit.wikimedia.org/r/384933 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9b91f759d2aecf0aceae00c84a30fb9deabee1d7 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: SanthoshGerrit-Reviewer: Catrope Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Clarify section Id and section number difference
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384933 ) Change subject: CX2: Clarify section Id and section number difference .. CX2: Clarify section Id and section number difference Section Id is sectionIdPrefix+ Section number Also, make sure section number is incremented unconditionally. This will help restoring sections from a saved translation when a new section from source article get support at later point. Otherwise that newly supported section in source will cause all section number order go wrong. Change-Id: I9b91f759d2aecf0aceae00c84a30fb9deabee1d7 --- M modules/dm/mw.cx.dm.Translation.js 1 file changed, 8 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/33/384933/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index 1856841..fca6cda 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -70,7 +70,7 @@ */ mw.cx.dm.Translation.static.getSourceDom = function ( sourceHtml, forTarget, savedTranslationUnits ) { var lastAboutGroup, - nextSectionId = 1, + sectionNumber = 0, sectionIdPrefix = forTarget ? 'cxTargetSection' : 'cxSourceSection', domDoc = ve.init.target.parseDocument( sourceHtml, 'visual' ), articleNode = domDoc.createElement( 'article' ), @@ -89,10 +89,12 @@ // Wrap each top-level element with a // TODO: it would be better to do section wrapping on the CX server Array.prototype.forEach.call( domDoc.body.childNodes, function ( node ) { - var sectionNode, aboutGroup; - if ( forTarget && savedTranslationUnits && savedTranslationUnits[ nextSectionId ] ) { - sectionNode = this.getSavedTranslation( savedTranslationUnits[ nextSectionId ] ); - nextSectionId++; + var sectionNode, aboutGroup, sectionId; + + sectionNumber++; + sectionId = sectionIdPrefix + sectionNumber; + if ( forTarget && savedTranslationUnits && savedTranslationUnits[ sectionNumber ] ) { + sectionNode = this.getSavedTranslation( savedTranslationUnits[ sectionNumber ] ); } else { if ( node.nodeType !== Node.ELEMENT_NODE ) { return; @@ -105,11 +107,9 @@ if ( ( aboutGroup && aboutGroup === lastAboutGroup ) ) { lastAboutGroup = aboutGroup; } else { - sectionNode.setAttribute( 'id', sectionIdPrefix + nextSectionId ); + sectionNode.setAttribute( 'id', sectionId ); sectionNode.setAttribute( 'rel', forTarget ? 'cx:Placeholder' : 'cx:Section' ); - nextSectionId++; } - } if ( forTarget ) { node.parentNode.removeChild( node ); -- To view, visit https://gerrit.wikimedia.org/r/384933 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b91f759d2aecf0aceae00c84a30fb9deabee1d7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits