Amire80 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/183834
Change subject: Handle unidirectional language pairs in the selector
......................................................................
Handle unidirectional language pairs in the selector
It may happen that a language is available as a source,
but not as a target. In this case, it may happen that
the source language selector will remain empty.
If this happens, try to pick the first available valid languages.
Bug: T86137
Change-Id: I8b4c53eaabc6db3a842357656323881a61b292b6
---
M modules/source/ext.cx.source.selector.js
1 file changed, 20 insertions(+), 3 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/34/183834/1
diff --git a/modules/source/ext.cx.source.selector.js
b/modules/source/ext.cx.source.selector.js
index 6980d88..7ef184f 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -810,8 +810,9 @@
};
CXSourceSelector.prototype.setDefaultLanguages = function () {
- var sourceLanguage, targetLanguage,
- storedSourceLanguage, storedTargetLanguage;
+ var contentLanguage,
+ storedTargetLanguage, targetLanguage,
+ storedSourceLanguage, sourceLanguage;
// If there is a target language code in localStorage, use that.
// Otherwise default to wiki content language.
@@ -819,7 +820,8 @@
storedTargetLanguage = localStorage.getItem(
'cxTargetLanguage' );
}
- targetLanguage = storedTargetLanguage || mw.config.get(
'wgContentLanguage' );
+ contentLanguage = mw.config.get( 'wgContentLanguage' );
+ targetLanguage = storedTargetLanguage || contentLanguage;
// If there is a source language code in localStorage and it is
valid
// for the target language, use that.
@@ -834,6 +836,21 @@
sourceLanguage = sourceLanguage ||
this.getValidSourceLanguages( targetLanguage )[ 0 ];
+ if ( !sourceLanguage ) {
+ if ( $.inArray( contentLanguage, this.sourceLanguages )
> -1 ) {
+ // If the content language is available as a
possible source language,
+ // set it as the source, because the user
probably wants to translate from it
+ sourceLanguage = contentLanguage;
+ } else {
+ // Give up: just set the first available source
language
+ sourceLanguage = this.sourceLanguages[0];
+ }
+ }
+
+ if ( sourceLanguage === targetLanguage ) {
+ targetLanguage = this.getValidTargetLanguages(
sourceLanguage )[0];
+ }
+
// Set the source language
this.setSourceLanguage( sourceLanguage );
--
To view, visit https://gerrit.wikimedia.org/r/183834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8b4c53eaabc6db3a842357656323881a61b292b6
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