From c9c21f9cbf0ff48e0a22fcf8f5f9987229624116 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 14 Apr 2019 18:20:57 -0400 Subject: [PATCH] Add more languages for list selection at install/reset time Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/501 Also, the handling of 3-letter language codes has been fixed. --- assets/assets.json | 14 +++++++------- src/js/storage.js | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/assets/assets.json b/assets/assets.json index 0b1503008..ef2c2b2d1 100644 --- a/assets/assets.json +++ b/assets/assets.json @@ -311,7 +311,7 @@ "group": "regions", "off": true, "title": "BGR: Bulgarian Adblock list", - "lang": "bg", + "lang": "bg mk", "contentURL": "https://stanev.org/abp/adblock_bg.txt", "supportURL": "https://stanev.org/abp/" }, @@ -387,7 +387,7 @@ "group": "regions", "off": true, "title": "FRA: EasyList Liste FR", - "lang": "ar fr", + "lang": "ar br fr oc", "contentURL": "https://easylist-downloads.adblockplus.org/liste_fr.txt", "supportURL": "https://forums.lanik.us/viewforum.php?f=91" }, @@ -514,7 +514,7 @@ "group": "regions", "off": true, "title": "NLD: EasyList Dutch", - "lang": "nl", + "lang": "af fy nl", "contentURL": "https://easylist-downloads.adblockplus.org/easylistdutch.txt", "supportURL": "https://forums.lanik.us/viewforum.php?f=100" }, @@ -566,7 +566,7 @@ "group": "regions", "off": true, "title": "RUS: RU AdList", - "lang": "be ru uk", + "lang": "be kk ru uk uz", "contentURL": "https://easylist-downloads.adblockplus.org/advblock+cssfixes.txt", "supportURL": "https://forums.lanik.us/viewforum.php?f=102", "instructionURL": "https://forums.lanik.us/viewtopic.php?f=102&t=22512" @@ -576,7 +576,7 @@ "group": "regions", "off": true, "title": "RUS: AdGuard Russian filter", - "lang": "be ru uk", + "lang": "be kk ru uk uz", "contentURL": "https://filters.adtidy.org/extension/ublock/filters/1.txt", "supportURL": "https://forum.adguard.com/forumdisplay.php?69-%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80%D1%8B-Adguard", "instructionURL": "https://kb.adguard.com/ru/general/adguard-ad-filters#russian" @@ -586,7 +586,7 @@ "group": "regions", "off": true, "title": "spa: EasyList Spanish", - "lang": "es", + "lang": "an ast ca es eu gl", "contentURL": "https://easylist-downloads.adblockplus.org/easylistspanish.txt", "supportURL": "https://forums.lanik.us/viewforum.php?f=103" }, @@ -595,7 +595,7 @@ "group": "regions", "off": true, "title": "spa, por: AdGuard Spanish/Portuguese filter", - "lang": "es pt", + "lang": "an ast ca es eu gl pt", "contentURL": "https://filters.adtidy.org/extension/ublock/filters/9.txt", "supportURL": "https://github.com/AdguardTeam/AdguardFilters#adguard-filters", "instructionURL": "https://kb.adguard.com/en/general/adguard-ad-filters" diff --git a/src/js/storage.js b/src/js/storage.js index ba0c732b6..3cf4ed4d9 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -1248,19 +1248,21 @@ // Support ability to auto-enable a filter list based on user agent. µBlock.listMatchesEnvironment = function(details) { - var re; // Matches language? if ( typeof details.lang === 'string' ) { - re = this.listMatchesEnvironment.reLang; + let re = this.listMatchesEnvironment.reLang; if ( re === undefined ) { - re = new RegExp('\\b' + self.navigator.language.slice(0, 2) + '\\b'); - this.listMatchesEnvironment.reLang = re; + const match = /^[a-z]+/.exec(self.navigator.language); + if ( match !== null ) { + re = new RegExp('\\b' + match[0] + '\\b'); + this.listMatchesEnvironment.reLang = re; + } } - if ( re.test(details.lang) ) { return true; } + if ( re !== undefined && re.test(details.lang) ) { return true; } } // Matches user agent? if ( typeof details.ua === 'string' ) { - re = new RegExp('\\b' + this.escapeRegex(details.ua) + '\\b', 'i'); + let re = new RegExp('\\b' + this.escapeRegex(details.ua) + '\\b', 'i'); if ( re.test(self.navigator.userAgent) ) { return true; } } return false;