Resolve language code redirects before using them in ULS

Interlanguage lists can contain language codes that are redirects
in language data of ULS.
For example, sr is a redirect to sr-cyrl.

So, if sr is passes as one of the language to ULS, its region, script
grouping is failing and the end result will be missing them in the ULS
language list. This should be properly fixed in jquery.uls library.
Tracked at https://github.com/wikimedia/jquery.uls/issues/207

In this patch we are following a simple approach of passing the language
codes to ULS as redirect resolved.

Bug: T100002
Bug: T131005
Bug: T126909
Bug: T123834
Change-Id: I8b89edb60b4d2c6f2b25c8589569f748c5523722
This commit is contained in:
Federico Leva
2016-04-02 13:20:49 +02:00
committed by Niklas Laxström
parent d013ae5ebf
commit 6ffd42c07a

View File

@@ -82,7 +82,7 @@
var language; var language;
for ( language in this.compactList ) { for ( language in this.compactList ) {
this.showLanguage( language ); this.compactList[ language ].element.parentNode.style.display = '';
} }
this.addTrigger(); this.addTrigger();
@@ -137,8 +137,13 @@
this.$menu.css( 'left', this.left ); this.$menu.css( 'left', this.left );
}, },
languageDecorator: function ( $languageLink, language ) { languageDecorator: function ( $languageLink, language ) {
// set href according to language // set href and text exactly same as what was in
$languageLink.prop( 'href', compactLinks.interlanguageList[ language ].href ); // interlanguage link. The ULS autonym might be different in some
// cases like sr. In ULS it is "српски", while in interlanguage links
// it is "српски / srpski"
$languageLink
.prop( 'href', compactLinks.interlanguageList[ language ].href )
.text( compactLinks.interlanguageList[ language ].autonym );
}, },
// Use compact version of ULS // Use compact version of ULS
compact: true, compact: true,
@@ -267,9 +272,14 @@
var interlanguageList = {}; var interlanguageList = {};
this.$interlanguageList.find( 'li.interlanguage-link > a' ).each( function () { this.$interlanguageList.find( 'li.interlanguage-link > a' ).each( function () {
interlanguageList[ this.getAttribute( 'lang' ) ] = { var langCode = 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' ), href: this.getAttribute( 'href' ),
autonym: $( this ).text() autonym: $( this ).text(),
element: this
}; };
} ); } );
@@ -307,15 +317,6 @@
this.$interlanguageList.append( $trigger ); this.$interlanguageList.append( $trigger );
this.$trigger = $trigger; this.$trigger = $trigger;
},
/**
* Show a language from the interlanguage list
*
* @param {string} language
*/
showLanguage: function ( language ) {
this.$interlanguageList.find( '.interwiki-' + language ).css( 'display', '' );
} }
}; };