Show languages that appear in the page's text
This is just a simple search for elements with lang attribute. This will be executed only when previous languages, geo-IP based languages, browser, UI, content languages etc. are not filling the defined compact size. Bug: T70077 Change-Id: I77d1efa5e29deeaaf595753fb5519c8b70c7f2b5
This commit is contained in:
committed by
Niklas Laxström
parent
29cc89398a
commit
df70f941b2
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user