[MediaWiki-commits] [Gerrit] Support gallery translations - change (mediawiki...ContentTranslation)

2015-06-09 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Support gallery translations
..


Support gallery translations

Adapt the galleries from the source article to the target article.

Copy the images and translate the captions if MT present.
Editing gallery text won't be allowed at present
in the translation interface.

Testplan:
Translate Radimlja article from English to Spanish.
Special:ContentTranslationpage=Radimljafrom=ento=estargettitle=Radimlja
Just click on the gallery in the page. You should see the gallery
copied to the translation and the gallery captions translated
using Apertium.
Publish the article and you should see the following
wikitext in the published page.

== Galería ==
gallery
File:Radmilja 1.jpg|Radimlja
File:Radmilja 2.jpg|Señal en la entrada a Radimlja
File:Radmilja 3.jpg|Radimlja, stecak necrópolis
/gallery

Bug: T96159
Change-Id: I5f1768c336a46a5534af1f90688d530b97f04e00
---
M Resources.php
A modules/tools/ext.cx.tools.gallery.js
2 files changed, 61 insertions(+), 0 deletions(-)

Approvals:
  Amire80: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Resources.php b/Resources.php
index 286f2d1..6213de7 100644
--- a/Resources.php
+++ b/Resources.php
@@ -296,6 +296,7 @@
'ext.cx.progressbar',
'ext.cx.tools.dictionary',
'ext.cx.tools.formatter',
+   'ext.cx.tools.gallery',
'ext.cx.tools.images',
'ext.cx.tools.instructions',
'ext.cx.tools.link',
@@ -474,6 +475,12 @@
),
 ) + $resourcePaths;
 
+$wgResourceModules['ext.cx.tools.gallery'] = array(
+   'scripts' = array(
+   'tools/ext.cx.tools.gallery.js',
+   ),
+) + $resourcePaths;
+
 $wgResourceModules['ext.cx.tools.categories'] = array(
'scripts' = array(
'tools/ext.cx.tools.categories.js',
diff --git a/modules/tools/ext.cx.tools.gallery.js 
b/modules/tools/ext.cx.tools.gallery.js
new file mode 100644
index 000..f44cee2
--- /dev/null
+++ b/modules/tools/ext.cx.tools.gallery.js
@@ -0,0 +1,54 @@
+/**
+ * ContentTranslation Tools
+ * A tool that allows editors to translate pages from one language
+ * to another with the help of machine translation and other translation tools
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+( function ( $, mw ) {
+   'use strict';
+
+   function adaptGallery( $section ) {
+   var i, $sourceSection, galleryData, galleryWikiMarkup = '',
+   imageItems, caption, imageIndex = 0;
+
+   if ( !$section.is( '[typeof*=mw:Extension/gallery]' ) ) {
+   return;
+   }
+   $sourceSection = mw.cx.getSourceSection( $section.data( 
'source' ) );
+   galleryData = $sourceSection.data( 'mw' );
+   // Copy the translated gallery image captions to the data-mw
+   // so that parsoid can create the gallery tag with image 
items.
+   galleryWikiMarkup = galleryData.body.extsrc;
+   imageItems = galleryWikiMarkup.split( '\n' );
+   for ( i = 0; i  imageItems.length; i++ ) {
+   if ( imageItems[ i ].trim() ) {
+   // FIXME: Copying plain text of gallery text 
will definitely lose the html
+   // mark up in translation. What we need is 
Wikitext of the translated HTML.
+   // That require a restbase api call.
+   caption = $section.find( '.gallerytext' ).eq( 
imageIndex ).text().trim();
+   imageItems[ i ] = [ imageItems[ i ].split( '|' 
)[ 0 ], caption ].join( '|' );
+   imageIndex++;
+   }
+   }
+
+   galleryData.body.extsrc = imageItems.join( '\n' );
+   // Copy the data-mw to target section.
+   $section.attr( 'data-mw', JSON.stringify( galleryData ) );
+   // Ultimately, this should make parsoid generate the following 
Wikitext in published page
+   // gallery
+   // File:Radmilja 1.jpg|Radimlja
+   // File:Radmilja 2.jpg|Señal en la entrada a Radimlja
+   // File:Radmilja 3.jpg|Radimlja, stecak necrópolis
+   // /gallery
+   // Make the images readonly. We can only adapt them. Not 
allowing edits.
+   $section.find( 'li' ).attr( 'contenteditable', false );
+   }
+
+   $( function () {
+   mw.hook( 'mw.cx.translation.postMT' ).add( adaptGallery );
+   } );
+}( jQuery, mediaWiki ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: 

[MediaWiki-commits] [Gerrit] Support gallery translations - change (mediawiki...ContentTranslation)

2015-06-08 Thread Santhosh (Code Review)
Santhosh has uploaded a new change for review.

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

Change subject: Support gallery translations
..

Support gallery translations

Adapt the galleries in source article to target article.
Copy the images and translate(if MT present). Editing gallery text
won't be allowed at present.

Testplan:
Translate Radimlja article from English to Spanish.
Special:ContentTranslationpage=Radimljafrom=ento=estargettitle=Radimlja
Just click on the gallery in the page. You should see gallery copied to 
translation
and the gallery captions translated using Apertium.
Publish the article and you should see the following wikitext in the published 
page.

== Galería ==
gallery
File:Radmilja 1.jpg|Radimlja
File:Radmilja 2.jpg|Señal en la entrada a Radimlja
File:Radmilja 3.jpg|Radimlja, stecak necrópolis
/gallery

Bug: T96159
Change-Id: I5f1768c336a46a5534af1f90688d530b97f04e00
---
M Resources.php
A modules/tools/ext.cx.tools.gallery.js
2 files changed, 59 insertions(+), 0 deletions(-)


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

diff --git a/Resources.php b/Resources.php
index 4aa09dd..51b4f71 100644
--- a/Resources.php
+++ b/Resources.php
@@ -296,6 +296,7 @@
'ext.cx.progressbar',
'ext.cx.tools.dictionary',
'ext.cx.tools.formatter',
+   'ext.cx.tools.gallery',
'ext.cx.tools.images',
'ext.cx.tools.instructions',
'ext.cx.tools.link',
@@ -470,6 +471,12 @@
),
 ) + $resourcePaths;
 
+$wgResourceModules['ext.cx.tools.gallery'] = array(
+   'scripts' = array(
+   'tools/ext.cx.tools.gallery.js',
+   ),
+) + $resourcePaths;
+
 $wgResourceModules['ext.cx.tools.categories'] = array(
'scripts' = array(
'tools/ext.cx.tools.categories.js',
diff --git a/modules/tools/ext.cx.tools.gallery.js 
b/modules/tools/ext.cx.tools.gallery.js
new file mode 100644
index 000..a5699e1
--- /dev/null
+++ b/modules/tools/ext.cx.tools.gallery.js
@@ -0,0 +1,52 @@
+/**
+ * ContentTranslation Tools
+ * A tool that allows editors to translate pages from one language
+ * to another with the help of machine translation and other translation tools
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+( function ( $, mw ) {
+   'use strict';
+
+   function adaptGallery( $section ) {
+   var i, $sourceSection, galleryData, galleryWikiMarkup = '',
+   imageItems, caption, imageIndex = 0;
+
+   if ( !$section.is( '[typeof*=mw:Extension/gallery]' ) ) {
+   return;
+   }
+   $sourceSection = mw.cx.getSourceSection( $section.data( 
'source' ) );
+   galleryData = $sourceSection.data( 'mw' );
+   // Copy the translated gallery image captions to the data-mw
+   // so that parsoid can create the gallery tag with image 
items.
+   galleryWikiMarkup = galleryData.body.extsrc;
+   imageItems = galleryWikiMarkup.split( '\n' );
+   for ( i = 0; i  imageItems.length; i++ ) {
+   if ( imageItems[ i ].trim() ) {
+   // FIXME: Copying plain text of gallery text 
will definitely lose the html
+   // mark up in translation. What we need is 
Wikitext of the translated HTML.
+   // That require a restbase api call.
+   caption = $section.find( '.gallerytext' ).eq( 
imageIndex ).text().trim();
+   imageItems[ i ] = [ imageItems[ i ].split( '|' 
)[ 0 ], caption ].join( '|' );
+   imageIndex++;
+   }
+   }
+
+   galleryData.body.extsrc = imageItems.join( '\n' );
+   // Copy the data-mw to target section.
+   $section.attr( 'data-mw', JSON.stringify( galleryData ) );
+   // Ultimately, this should make parsoid generate the following 
Wikitext in published page
+   // gallery
+   // File:Radmilja 1.jpg|Radimlja
+   // File:Radmilja 2.jpg|Señal en la entrada a Radimlja
+   // File:Radmilja 3.jpg|Radimlja, stecak necrópolis
+   // /gallery
+   }
+
+   $( function () {
+   mw.hook( 'mw.cx.translation.postMT' ).add( adaptGallery );
+   } );
+}( jQuery, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f1768c336a46a5534af1f90688d530b97f04e00
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh