From 5cfefa78359ddcd0f9f002b30337916efab99763 Mon Sep 17 00:00:00 2001 From: Dale Harvey Date: Fri, 30 Aug 2019 15:02:47 +0000 Subject: [PATCH] Bug 1572470 - Add wikipedia to engines.json r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D43768 --HG-- extra : moz-landing-system : lando --- .../components/search/extensions/engines.json | 72 +++++++++++++++++++ .../search/SearchEngineSelector.jsm | 6 ++ .../search/docs/SearchEngineConfiguration.rst | 23 ++++++ .../tests/xpcshell/test_engine_selector.js | 4 +- 4 files changed, 103 insertions(+), 2 deletions(-) diff --git a/browser/components/search/extensions/engines.json b/browser/components/search/extensions/engines.json index d730c7a37e47..047308ccf0b4 100644 --- a/browser/components/search/extensions/engines.json +++ b/browser/components/search/extensions/engines.json @@ -808,6 +808,78 @@ "webExtensionId": "zoznam-sk@search.mozilla.org", "webExtensionVersion": "1.2", "appliesTo": [{ "included": { "locales": { "matches": ["sk"]}}}] + }, + { + "engineName": "wikipedia", + "webExtensionId": "wikipedia@search.mozilla.org", + "webExtensionVersion": "1.0", + "appliesTo": [ { + "included": { "locales": { "matches": [ + "af", "an", "ar", "as", "ast", "az", "be", "bg", + "br", "bs", "ca", "crh", "cy", "da", "de", "dsb", + "el", "eo", "et", "eu", "fa", "fi", "fy-NL", "ga-IE", + "gd", "gl", "gn", "he", "hr", "hsb", "hu", "ia", + "id", "is", "it", "ka", "kab", "kk", "km", "kn", + "lij", "lo", "lt", "ltg", "lv", "mk", "ml", "mr", + "ms", "my", "nl", "oc", "or", "pl", "rm", "ro", "ru", + "si", "sk", "sl", "sq", "sr", "sv-SE", "ta", "te", + "th", "tl", "tr", "uk", "ur", "uz", "vi", "wo", + "zh-CN", "zh-TW" + ]}}, + "webExtensionLocale": "$USER_LOCALE" + }, { + "included": { "locales": { "matches": [ + "en-CA", "en-GB", "en-US", "en-ZA", "ach", "xh" + ]}}, + "webExtensionLocale": "en" + }, { + "included": { "locales": { "matches": [ "bn", "bn-BD", "bn-IN" ] } }, + "webExtensionLocale": "bn" + }, { + "included": { "locales": { "matches": [ + "cak", "es-AR", "es-CL", "es-ES", "es-MX", "trs" + ]}}, + "webExtensionLocale": "es" + }, { + "included": { "locales": { "matches": [ "cs" ] } }, + "webExtensionLocale": "cz" + }, { + "included": { "locales": { "matches": [ "ff", "fr", "son" ] } }, + "webExtensionLocale": "fr" + }, { + "included": { "locales": { "matches": [ "gu-IN" ] } }, + "webExtensionLocale": "gu" + }, { + "included": { "locales": { "matches": [ "hi-IN" ] } }, + "webExtensionLocale": "hi" + }, { + "included": { "locales": { "matches": [ "hy-AM" ] } }, + "webExtensionLocale": "hy" + }, { + "included": { "locales": { "matches": [ "ja-JP-macos", "ja" ] } }, + "webExtensionLocale": "ja" + }, { + "included": { "locales": { "matches": [ "ko" ] } }, + "webExtensionLocale": "kr" + }, { + "included": { "locales": { "matches": [ "mai" ] } }, + "webExtensionLocale": "hi" + }, { + "included": { "locales": { "matches": [ "nb-NO" ] } }, + "webExtensionLocale": "NO" + }, { + "included": { "locales": { "matches": [ "ne-NP" ] } }, + "webExtensionLocale": "ne" + }, { + "included": { "locales": { "matches": [ "nn-NO" ] } }, + "webExtensionLocale": "NN" + }, { + "included": { "locales": { "matches": [ "pa-IN" ] } }, + "webExtensionLocale": "pa" + }, { + "included": { "locales": { "matches": [ "pt-BR", "pt-PT" ] } }, + "webExtensionLocale": "pt" + }] } ] } diff --git a/toolkit/components/search/SearchEngineSelector.jsm b/toolkit/components/search/SearchEngineSelector.jsm index eec0096b56c2..b75930baeb27 100644 --- a/toolkit/components/search/SearchEngineSelector.jsm +++ b/toolkit/components/search/SearchEngineSelector.jsm @@ -18,6 +18,7 @@ XPCOMUtils.defineLazyModuleGetters(this, { const EXT_SEARCH_PREFIX = "resource://search-extensions/"; const ENGINE_CONFIG_URL = `${EXT_SEARCH_PREFIX}engines.json`; +const USER_LOCALE = "$USER_LOCALE"; function log(str) { SearchUtils.log("SearchEngineSelector " + str + "\n"); @@ -77,6 +78,11 @@ class SearchEngineSelector { for (let section of applies) { this._copyObject(baseConfig, section); } + + if (baseConfig.webExtensionLocale == USER_LOCALE) { + baseConfig.webExtensionLocale = locale; + } + engines.push(baseConfig); } } diff --git a/toolkit/components/search/docs/SearchEngineConfiguration.rst b/toolkit/components/search/docs/SearchEngineConfiguration.rst index 5da9814dc0a6..99671f225b8a 100644 --- a/toolkit/components/search/docs/SearchEngineConfiguration.rst +++ b/toolkit/components/search/docs/SearchEngineConfiguration.rst @@ -109,6 +109,29 @@ In this case users identified as being in the US region would use the WebExtensi with identifier ``webext-engine1``, version 1.1. GB region users would get ``webext-gb`` version 1.2, and all other users would get ``webext`` version 1.0. +Special Attributes +------------------ + +If a ``webExtensionLocale`` attribute is specified with the value +``"$USER_LOCALE"`` then the special value will be replaced in the +configuration object with the users locale. For example: + +.. code-block:: js + + "engine1": { + "webExtensionId": "webext", + "webExtensionVersion": "1.0", + "appliesTo": [{ + "included": { + "locales": { + "matches": ["us", "gb"] + }, + "webExtensionLocale": "$USER_LOCALE", + }, + +Will report either ``us`` or ``gb`` as the ``webExtensionLocale`` +depending on the user. + Engine Defaults --------------- diff --git a/toolkit/components/search/tests/xpcshell/test_engine_selector.js b/toolkit/components/search/tests/xpcshell/test_engine_selector.js index e4dabae4d45c..3916f3fab629 100644 --- a/toolkit/components/search/tests/xpcshell/test_engine_selector.js +++ b/toolkit/components/search/tests/xpcshell/test_engine_selector.js @@ -21,7 +21,7 @@ const CONFIG_URL = }, { included: { regions: ["us"] }, - webExtensionLocale: "us", + webExtensionLocale: "$USER_LOCALE", }, ], }, @@ -80,7 +80,7 @@ add_task(async function() { Assert.deepEqual(names, ["lycos", "altavista", "aol"], "Correct order"); Assert.equal( engines[2].webExtensionLocale, - "us", + "en-US", "Subsequent matches in applies to can override default" );