Santhosh has uploaded a new change for review.

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

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 lang attribute.

This will be executed only when previous languages, geo-IP based languages,
browser, UI, content languages etc not filling the defined compact size(9)

Bug: T70077
Change-Id: I77d1efa5e29deeaaf595753fb5519c8b70c7f2b5
---
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/55/298255/1

diff --git a/resources/js/ext.uls.compactlinks.js 
b/resources/js/ext.uls.compactlinks.js
index 5d5b771..2e3f9d4 100644
--- a/resources/js/ext.uls.compactlinks.js
+++ b/resources/js/ext.uls.compactlinks.js
@@ -229,6 +229,8 @@
                        // Add all common languages to the beginning of array.
                        // These are the most probable languages predicted by 
ULS.
                        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
                        getExtraCommonLanguages,
                        // Finally add the whole languages array too.
@@ -326,6 +328,29 @@
        }
 
        /**
+        * 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 ) {
+                       languagesInText.push( $( el ).attr( 'lang' ) );
+               } );
+
+               return $.grep( languagesInText, function ( language ) {
+                       return $.inArray( language, languages ) >= 0;
+               } );
+       };
+
+       /**
         * Find out the existing languages supported
         * by the article and fetch their href.
         *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77d1efa5e29deeaaf595753fb5519c8b70c7f2b5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>

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

Reply via email to