Merge "Show languages that appear in the page's text"

This commit is contained in:
jenkins-bot
2016-08-01 06:31:24 +00:00
committed by Gerrit Code Review

View File

@@ -229,6 +229,8 @@
// Add all common languages to the beginning of array. // Add all common languages to the beginning of array.
// These are the most probable languages predicted by ULS. // These are the most probable languages predicted by ULS.
this.getCommonLanguages, this.getCommonLanguages,
// Add languages that are present in the article content.
this.filterByLangsInText,
// Some global fallbacks to avoid showing languages in the beginning of the alphabet // Some global fallbacks to avoid showing languages in the beginning of the alphabet
getExtraCommonLanguages, getExtraCommonLanguages,
// Finally add the whole languages array too. // Finally add the whole languages array too.
@@ -325,6 +327,30 @@
return []; return [];
} }
/**
* Filter the language list by languages that appear in
* the page's text. This is done by looking for HTML elements with
* a "lang" attribute—they are likely to appear in a foreign name,
* for example.
*
* The reader doesn't necessarily know this language, but it
* appears relevant to the page.
*
* @return {Array} List of language codes supported by the article
*/
CompactInterlanguageList.prototype.filterByLangsInText = function ( languages ) {
var languagesInText = [];
$( '#mw-content-text [lang]' ).each( function ( i, el ) {
var lang = $( el ).attr( 'lang' );
if ( $.inArray( lang, languagesInText ) === -1 && $.inArray( lang, languages ) >= 0 ) {
languagesInText.push( lang );
}
} );
return languagesInText;
};
/** /**
* Find out the existing languages supported * Find out the existing languages supported
* by the article and fetch their href. * by the article and fetch their href.