Amire80 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/209315
Change subject: Don't let source and target languages be the same
......................................................................
Don't let source and target languages be the same
* When filling the target languages, remove the source language
from the selectable languages list.
* When selecting the same source language as the target language,
swap them instead.
Bug: T96573
Change-Id: I826e0ebd288770706fcb3d96eccc3c8fc5bd80a9
---
M modules/source/ext.cx.source.selector.js
1 file changed, 17 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/15/209315/1
diff --git a/modules/source/ext.cx.source.selector.js
b/modules/source/ext.cx.source.selector.js
index 2cec8fd..2ccab3e 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -189,6 +189,12 @@
* @param {string} language A language code
*/
CXSourceSelector.prototype.setSourceLanguage = function ( language ) {
+ // Don't let the same languages be selected as source and
target.
+ // Instead, do what the user probably means and swap them.
+ if ( language === this.getTargetLanguage() ) {
+ this.setTargetLanguage( this.getSourceLanguage() );
+ }
+
this.setLanguage( language, this.$sourceLanguage,
'cxSourceLanguage' );
};
@@ -213,17 +219,24 @@
* language tools compatible with the source language.
*/
CXSourceSelector.prototype.fillTargetLanguages = function () {
- var cxSourceSelector = this,
+ var targetLanguageCodes, sourceLanguage,
+ cxSourceSelector = this,
targetUlsClass = 'cx-sourceselector-uls-target';
// Delete the old target ULS
$( '.' + targetUlsClass ).remove();
this.$targetLanguage.data( 'uls', null );
+ // Don't let the target be the same as source
+ sourceLanguage = this.getSourceLanguage();
+ targetLanguageCodes = jQuery.grep( this.targetLanguages,
function( language ) {
+ return language !== sourceLanguage;
+ } );
+
// Create a new target ULS
this.$targetLanguage.uls( {
- languages: getAutonyms( this.targetLanguages ),
- menuWidth: getUlsMenuWidth( this.targetLanguages.length
),
+ languages: getAutonyms( targetLanguageCodes ),
+ menuWidth: getUlsMenuWidth( targetLanguageCodes.length
),
onSelect: function ( language ) {
cxSourceSelector.targetLanguageChangeHandler(
language );
cxSourceSelector.updatePreviousLanguages(
language );
@@ -233,7 +246,7 @@
},
quickList: function () {
return mw.uls.getFrequentLanguageList().filter(
function ( n ) {
- return
cxSourceSelector.targetLanguages.indexOf( n ) !== -1;
+ return targetLanguageCodes.indexOf( n )
!== -1;
} );
},
compact: true
--
To view, visit https://gerrit.wikimedia.org/r/209315
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I826e0ebd288770706fcb3d96eccc3c8fc5bd80a9
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