Amire80 has uploaded a new change for review.

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

Change subject: Make language selection saner
......................................................................

Make language selection saner

* Add the $wgContentTranslationDefaultSourceLanguage variable,
  set to English by default. (Can be useful to set it to Russian,
  French, or some other language in relevant wikis).
* Set the target language to the content language by default.
  The current logic frequently caused the content language
  to become the source language.
* Add the language in the selector to ULS' previous languages
  only if the user actually selected it.

Bug: T94869
Change-Id: Ia11e455aca350a942667fec982dee298abe0e127
---
M ContentTranslation.hooks.php
M ContentTranslation.php
M modules/source/ext.cx.source.selector.js
3 files changed, 25 insertions(+), 32 deletions(-)


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

diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 7b042c7..c95aafe 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -140,6 +140,7 @@
                        $wgContentTranslationSiteTemplates,
                        $wgContentTranslationCampaigns,
                        $wgContentTranslationBrowserBlacklist,
+                       $wgContentTranslationDefaultSourceLanguage,
                        $wgContentTranslationTargetNamespace;
 
                $vars['wgContentTranslationTranslateInTarget'] = 
$wgContentTranslationTranslateInTarget;
@@ -148,6 +149,7 @@
                $vars['wgContentTranslationSiteTemplates'] = 
$wgContentTranslationSiteTemplates;
                $vars['wgContentTranslationCampaigns'] = 
$wgContentTranslationCampaigns;
                $vars['wgContentTranslationBrowserBlacklist'] = 
$wgContentTranslationBrowserBlacklist;
+               $vars['wgContentTranslationDefaultSourceLanguage'] = 
$wgContentTranslationDefaultSourceLanguage;
                $vars['wgContentTranslationTargetNamespace'] = 
$wgContentTranslationTargetNamespace;
        }
 
diff --git a/ContentTranslation.php b/ContentTranslation.php
index 149c0a3..d29aae7 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -137,6 +137,12 @@
 $GLOBALS['wgContentTranslationAsBetaFeature'] = true;
 
 /*
+ * The default source language.
+ * English is the default.
+ */
+$GLOBALS['wgContentTranslationDefaultSourceLanguage'] = 'en';
+
+/*
  * Target namespace to publish articles. Values can be 'Main'
  * or any valid Namespace without leading column.
  * Example: 'User', 'MediaWiki', 'Draft'
diff --git a/modules/source/ext.cx.source.selector.js 
b/modules/source/ext.cx.source.selector.js
index d928bfa..2cec8fd 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -174,8 +174,6 @@
                if ( window.localStorage ) {
                        localStorage.setItem( localStorageItem, language );
                }
-
-               this.updatePreviousLanguages( language );
        };
 
        /**
@@ -228,6 +226,7 @@
                        menuWidth: getUlsMenuWidth( this.targetLanguages.length 
),
                        onSelect: function ( language ) {
                                cxSourceSelector.targetLanguageChangeHandler( 
language );
+                               cxSourceSelector.updatePreviousLanguages( 
language );
                        },
                        onReady: function () {
                                this.$menu.addClass( targetUlsClass );
@@ -303,6 +302,7 @@
                if ( language === this.getSourceLanguage() ) {
                        return;
                }
+
                this.setTargetLanguage( language );
                this.check();
        };
@@ -727,43 +727,27 @@
        };
 
        CXSourceSelector.prototype.setDefaultLanguages = function () {
-               var contentLanguage,
-                       storedTargetLanguage, targetLanguage,
-                       storedSourceLanguage, sourceLanguage;
+               var storedTargetLanguage, storedSourceLanguage,
+                       targetLanguage, sourceLanguage, i;
 
-               // If there is a target language code in localStorage, use that.
-               // Otherwise default to wiki content language.
                if ( window.localStorage ) {
                        storedTargetLanguage = localStorage.getItem( 
'cxTargetLanguage' );
-               }
-
-               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.
-               // Otherwise use the first valid source language.
-               if ( window.localStorage ) {
                        storedSourceLanguage = localStorage.getItem( 
'cxSourceLanguage' );
-
-                       if ( this.isValidSource( storedSourceLanguage, 
targetLanguage ) ) {
-                               sourceLanguage = storedSourceLanguage;
-                       }
                }
 
-               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 ];
-                       }
-               }
+               targetLanguage = storedTargetLanguage || mw.config.get( 
'wgContentLanguage' );
+               sourceLanguage = storedSourceLanguage ||
+                       mw.config.get( 
'wgContentTranslationDefaultSourceLanguage' );
 
-               if ( sourceLanguage === targetLanguage ) {
-                       targetLanguage = this.targetLanguages[ 0 ];
+               // Shouldn't Happen, but just in case something is invalid - 
pick some other language
+               for ( i = 0; i < this.sourceLanguages.length; i++ ) {
+                       if ( sourceLanguage !== targetLanguage &&
+                               this.isValidSource( sourceLanguage, 
targetLanguage )
+                       ) {
+                               break;
+                       }
+
+                       sourceLanguage = this.sourceLanguages[ i ];
                }
 
                // Set the source language
@@ -812,6 +796,7 @@
                        menuWidth: getUlsMenuWidth( this.sourceLanguages.length 
),
                        onSelect: function ( language ) {
                                cxSourceSelector.sourceLanguageChangeHandler( 
language );
+                               cxSourceSelector.updatePreviousLanguages( 
language );
                        },
                        onReady: function () {
                                this.$menu.addClass( 
'cx-sourceselector-uls-source' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia11e455aca350a942667fec982dee298abe0e127
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

Reply via email to