Amire80 has uploaded a new change for review.

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

Change subject: Show languages that appear in the page's text
......................................................................

Show languages that appear in the page's text

This is just a simple search for elements with
a lang attribute.

The task suggests also limiting their number,
which is easy to do if needed.

Bug: T70077
Change-Id: Idfffdd250af1942c3ca73faffdf05c920392f013
---
M resources/js/ext.uls.compactlinks.js
1 file changed, 25 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector 
refs/changes/15/296615/1

diff --git a/resources/js/ext.uls.compactlinks.js 
b/resources/js/ext.uls.compactlinks.js
index a050cf5..99a6786 100644
--- a/resources/js/ext.uls.compactlinks.js
+++ b/resources/js/ext.uls.compactlinks.js
@@ -237,6 +237,9 @@
                                // These are the most probable languages 
predicted by ULS.
                                this.getCommonLanguages( languages ),
 
+                               // Add languages text in which appears in the 
page itself
+                               this.filterByLangsInText( languages ),
+
                                // Some global fallbacks to avoid showing 
languages in the beginning of the alphabet
                                this.getExtraCommonLanguages( languages ),
 
@@ -269,6 +272,28 @@
                },
 
                /**
+                * 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
+                */
+               filterByLangsInText: function ( languages ) {
+                   var languagesInText = [];
+
+                   $( '#mw-content-text [lang]' ).each( function ( i, el ) {
+                       languagesInText.push( $( el ).attr( 'lang' ) );
+                   } );
+
+                   return $.grep( languagesInText, function ( language ) {
+                       return $.inArray( language, languages ) >= 0;
+                   } );
+               },
+
+               /**
                 * Filter the language list by common languages.
                 * Common languages are the most probable languages predicted 
by ULS.
                 *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idfffdd250af1942c3ca73faffdf05c920392f013
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Amire80 <amir.ahar...@mail.huji.ac.il>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to