Amire80 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/159541
Change subject: Get all language pairs in the selector from the server
......................................................................
Get all language pairs in the selector from the server
Depends on Iccfeea709a21472813d69bf9b86f4aca2dae275c
Change-Id: I35b8a690769228635766137e75fa93949c1def0a
---
M modules/source/ext.cx.source.selector.js
1 file changed, 69 insertions(+), 9 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/41/159541/1
diff --git a/modules/source/ext.cx.source.selector.js
b/modules/source/ext.cx.source.selector.js
index f905dcb..c998f44 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -12,6 +12,47 @@
'use strict';
/**
+ * Get all the source and target languages.
+ * @return {jQuery.Promise}
+ */
+ function getLanguagePairs() {
+ var languagePairsUrl = mw.config.get(
'wgContentTranslationServerURL' ) + '/languagepairs';
+
+ if ( CXSourceSelector.languagePairs ) {
+ return $.Deferred().resolve();
+ }
+
+ return $.get( languagePairsUrl )
+ .done( function ( response ) {
+ var i, sourceLanguage, targetLanguage,
+ languagePairs = response,
+ backwardsLanguagePairs = {};
+
+ for ( sourceLanguage in languagePairs ) {
+ for( i = 0; i < languagePairs[
sourceLanguage ].length; i++ ) {
+ targetLanguage = languagePairs[
sourceLanguage ][ i ];
+
+ if ( !backwardsLanguagePairs[
targetLanguage ] ) {
+ backwardsLanguagePairs[
targetLanguage ] = [];
+ }
+
+ backwardsLanguagePairs[
targetLanguage ].push( sourceLanguage );
+ }
+ }
+
+ CXSourceSelector.languagePairs = languagePairs;
+ CXSourceSelector.backwardsLanguagePairs =
backwardsLanguagePairs;
+ } )
+ .fail( function ( response ) {
+ mw.log(
+ 'Error getting language pairs from ' +
languagePairsUrl + ' . ' +
+ response.statusText + ' (' +
response.status + '). ' +
+ response.responseText
+ );
+ } );
+ }
+
+ /**
* CXSourceSelector
* @class
*/
@@ -246,18 +287,37 @@
} );
};
+ /**
+ * For the given array, remove duplicates
+ * @param {Array} originalArray
+ * @return de-duplicated array
+ */
+ function unique( originalArray ) {
+ var uniqueArray = [];
+
+ $.each( originalArray, function ( i, v ) {
+ if ( $.inArray( v, uniqueArray ) === -1 ) {
+ uniqueArray.push( v );
+ }
+ } );
+
+ return uniqueArray;
+ }
+
+
$( function () {
mw.hook( 'mw.cx.source.select' ).add( function () {
- var $container;
+ getLanguagePairs().done( function () {
+ var $container = $( '.cx-widget__columns' );
- $container = $( '.cx-widget__columns' );
- $container.empty().cxSourceSelector( {
- top: '150px',
- left: '33%',
- // TODO Get a list from configuration
- sourceLanguages: [ 'es' ],
- targetLanguages: [ 'ca' ]
- } ).click();
+ $container.empty().cxSourceSelector( {
+ top: '150px',
+ left: '33%',
+ // TODO Get a list from configuration
+ sourceLanguages: Object.keys(
CXSourceSelector.languagePairs ),
+ targetLanguages: Object.keys(
CXSourceSelector.backwardsLanguagePairs )
+ } ).click();
+ } );
} );
} );
}( jQuery, mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/159541
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I35b8a690769228635766137e75fa93949c1def0a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits