Get current language using extensions API (instead of `navigator.language`)

Related feedback:
- https://github.com/gorhill/uBlock/pull/3860
This commit is contained in:
Raymond Hill 2021-11-06 12:49:27 -04:00
parent 871f4abd39
commit 5daa6a7ff3
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 3 additions and 2 deletions

View File

@ -1489,16 +1489,17 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
// https://github.com/gorhill/uBlock/issues/2344
// Support mutliple locales per filter list.
// https://github.com/gorhill/uBlock/issues/3210
// Support ability to auto-enable a filter list based on user agent.
// https://github.com/gorhill/uBlock/pull/3860
// Get current language using extensions API (instead of `navigator.language`)
µb.listMatchesEnvironment = function(details) {
// Matches language?
if ( typeof details.lang === 'string' ) {
let re = this.listMatchesEnvironment.reLang;
if ( re === undefined ) {
const match = /^[a-z]+/.exec(self.navigator.language);
const match = /^[a-z]+/.exec(browser.i18n.getUILanguage());
if ( match !== null ) {
re = new RegExp('\\b' + match[0] + '\\b');
this.listMatchesEnvironment.reLang = re;