jenkins-bot has submitted this change and it was merged.

Change subject: ext.uls.compactlinks: consistently normalize language codes
......................................................................


ext.uls.compactlinks: consistently normalize language codes

Create a function for this purpose and use it everywhere where
language code is read from an attribute.

Bug: T143867
Change-Id: I01b6f04dd9185a9f4ab565e96ca5a6a34e4ea14a
(cherry picked from commit 2144019c50cb3a33847f8bcac3fbc2e23505bf0d)
---
M resources/js/ext.uls.compactlinks.js
1 file changed, 18 insertions(+), 6 deletions(-)

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



diff --git a/resources/js/ext.uls.compactlinks.js 
b/resources/js/ext.uls.compactlinks.js
index 581b84d..3174cbe 100644
--- a/resources/js/ext.uls.compactlinks.js
+++ b/resources/js/ext.uls.compactlinks.js
@@ -36,6 +36,20 @@
        }
 
        /**
+        * Normalize a language code for ULS usage.
+        *
+        * MediaWiki language codes (especially on WMF sites) are inconsistent
+        * with ULS codes. We need to use ULS codes to access the proper data.
+        *
+        * @param {string} code
+        * @return {string} Normalized language code
+        */
+       function convertMediaWikiLanguageCodeToULS( code ) {
+               code = code.toLowerCase();
+               return $.uls.data.isRedirect( code ) || code;
+       }
+
+       /**
         * @class
         */
        function CompactInterlanguageList( interlanguageList, options ) {
@@ -357,7 +371,7 @@
                var languagesInText = [];
 
                $( '#mw-content-text [lang]' ).each( function ( i, el ) {
-                       var lang = $( el ).attr( 'lang' );
+                       var lang = convertMediaWikiLanguageCodeToULS( $( el 
).attr( 'lang' ) );
                        if ( $.inArray( lang, languagesInText ) === -1 && 
$.inArray( lang, languages ) >= 0 ) {
                                languagesInText.push( lang );
                        }
@@ -378,8 +392,8 @@
         */
        CompactInterlanguageList.prototype.filterByBadges = function () {
                return $( '#p-lang' ).find( '[class*="badge"]' ).map( function 
( i, el ) {
-                       return $( el ).find( 'a' ).attr( 'lang' 
).toLowerCase(); }
-               ).toArray();
+                       return convertMediaWikiLanguageCodeToULS( $( el ).find( 
'a' ).attr( 'lang' ) );
+               } ).toArray();
        };
 
        /**
@@ -392,10 +406,8 @@
                var interlanguageList = {};
 
                this.$interlanguageList.find( 'li.interlanguage-link > a' 
).each( function () {
-                       var langCode = this.getAttribute( 'lang' 
).toLowerCase();
+                       var langCode = convertMediaWikiLanguageCodeToULS( 
this.getAttribute( 'lang' ) );
 
-                       // We keep interlanguageList with redirect resolved 
language codes as keys.
-                       langCode = $.uls.data.isRedirect( langCode ) || 
langCode;
                        interlanguageList[ langCode ] = {
                                href: this.getAttribute( 'href' ),
                                autonym: $( this ).text(),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I01b6f04dd9185a9f4ab565e96ca5a6a34e4ea14a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: wmf/1.28.0-wmf.16
Gerrit-Owner: KartikMistry <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Zfilipin <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to