mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1174468 - Show Yandex.Translate attribution when Yandex engine is selected. r=felipc
This commit is contained in:
parent
653e081fc1
commit
a6a05d817f
@ -18,6 +18,11 @@ var gContentPane = {
|
||||
if (Services.prefs.getBoolPref(prefName)) {
|
||||
let row = document.getElementById("translationBox");
|
||||
row.removeAttribute("hidden");
|
||||
// Showing attribution only for Bing Translator.
|
||||
Components.utils.import("resource:///modules/translation/Translation.jsm");
|
||||
if (Translation.translationEngine == "bing") {
|
||||
document.getElementById("bingAttribution").removeAttribute("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
let drmInfoURL =
|
||||
|
@ -163,11 +163,13 @@
|
||||
label="&translateWebPages.label;." accesskey="&translateWebPages.accesskey;"
|
||||
onsyncfrompreference="return gContentPane.updateButtons('translateButton',
|
||||
'browser.translation.detectLanguage');"/>
|
||||
<label>&translation.options.attribution.beforeLogo;</label>
|
||||
<image id="translationAttributionImage" aria-label="Microsoft Translator"
|
||||
onclick="gContentPane.openTranslationProviderAttribution()"
|
||||
src="chrome://browser/content/microsoft-translator-attribution.png"/>
|
||||
<label>&translation.options.attribution.afterLogo;</label>
|
||||
<hbox id="bingAttribution" hidden="true">
|
||||
<label>&translation.options.attribution.beforeLogo;</label>
|
||||
<image id="translationAttributionImage" aria-label="Microsoft Translator"
|
||||
onclick="gContentPane.openTranslationProviderAttribution()"
|
||||
src="chrome://browser/content/microsoft-translator-attribution.png"/>
|
||||
<label>&translation.options.attribution.afterLogo;</label>
|
||||
</hbox>
|
||||
</hbox>
|
||||
<button id="translateButton" label="&translateExceptions.label;"
|
||||
oncommand="gContentPane.showTranslationExceptions();"
|
||||
|
@ -23,6 +23,11 @@ var gContentPane = {
|
||||
if (Services.prefs.getBoolPref(prefName)) {
|
||||
let row = document.getElementById("translationBox");
|
||||
row.removeAttribute("hidden");
|
||||
// Showing attribution only for Bing Translator.
|
||||
Components.utils.import("resource:///modules/translation/Translation.jsm");
|
||||
if (Translation.translationEngine == "bing") {
|
||||
document.getElementById("bingAttribution").removeAttribute("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
setEventListener("font.language.group", "change",
|
||||
|
@ -160,12 +160,14 @@
|
||||
label="&translateWebPages.label;." accesskey="&translateWebPages.accesskey;"
|
||||
onsyncfrompreference="return gContentPane.updateButtons('translateButton',
|
||||
'browser.translation.detectLanguage');"/>
|
||||
<label>&translation.options.attribution.beforeLogo;</label>
|
||||
<separator orient="vertical" class="thin"/>
|
||||
<image id="translationAttributionImage" aria-label="Microsoft Translator"
|
||||
src="chrome://browser/content/microsoft-translator-attribution.png"/>
|
||||
<separator orient="vertical" class="thin"/>
|
||||
<label>&translation.options.attribution.afterLogo;</label>
|
||||
<hbox id="bingAttribution" hidden="true">
|
||||
<label>&translation.options.attribution.beforeLogo;</label>
|
||||
<separator orient="vertical" class="thin"/>
|
||||
<image id="translationAttributionImage" aria-label="Microsoft Translator"
|
||||
src="chrome://browser/content/microsoft-translator-attribution.png"/>
|
||||
<separator orient="vertical" class="thin"/>
|
||||
<label>&translation.options.attribution.afterLogo;</label>
|
||||
</hbox>
|
||||
</hbox>
|
||||
<button id="translateButton" label="&translateExceptions.label;"
|
||||
accesskey="&translateExceptions.accesskey;"/>
|
||||
|
@ -84,10 +84,34 @@ this.Translation = {
|
||||
},
|
||||
|
||||
openProviderAttribution: function() {
|
||||
let attribution = this.supportedEngines[this.translationEngine];
|
||||
Cu.import("resource:///modules/RecentWindow.jsm");
|
||||
RecentWindow.getMostRecentBrowserWindow().openUILinkIn(
|
||||
"http://aka.ms/MicrosoftTranslatorAttribution", "tab");
|
||||
}
|
||||
RecentWindow.getMostRecentBrowserWindow().openUILinkIn(attribution, "tab");
|
||||
},
|
||||
|
||||
/**
|
||||
* The list of translation engines and their attributions.
|
||||
*/
|
||||
supportedEngines: {
|
||||
"bing" : "http://aka.ms/MicrosoftTranslatorAttribution",
|
||||
"yandex" : "http://translate.yandex.com/"
|
||||
},
|
||||
|
||||
/**
|
||||
* Fallback engine (currently Bing Translator) if the preferences seem
|
||||
* confusing.
|
||||
*/
|
||||
get defaultEngine() {
|
||||
return this.supportedEngines.keys[0];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the name of the preferred translation engine.
|
||||
*/
|
||||
get translationEngine() {
|
||||
let engine = Services.prefs.getCharPref("browser.translation.engine");
|
||||
return Object.keys(this.supportedEngines).includes(engine) ? engine : this.defaultEngine;
|
||||
},
|
||||
};
|
||||
|
||||
/* TranslationUI objects keep the information related to translation for
|
||||
|
@ -8,18 +8,22 @@
|
||||
|
||||
const kEnginePref = "browser.translation.engine";
|
||||
const kApiKeyPref = "browser.translation.yandex.apiKeyOverride";
|
||||
const kShowUIPref = "browser.translation.ui.show";
|
||||
|
||||
const {YandexTranslator} = Cu.import("resource:///modules/translation/YandexTranslator.jsm", {});
|
||||
const {TranslationDocument} = Cu.import("resource:///modules/translation/TranslationDocument.jsm", {});
|
||||
const {Promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
const {Translation} = Cu.import("resource:///modules/translation/Translation.jsm", {});
|
||||
|
||||
add_task(function* setup() {
|
||||
Services.prefs.setCharPref(kEnginePref, "yandex");
|
||||
Services.prefs.setCharPref(kApiKeyPref, "yandexValidKey");
|
||||
Services.prefs.setBoolPref(kShowUIPref, true);
|
||||
|
||||
registerCleanupFunction(function () {
|
||||
Services.prefs.clearUserPref(kEnginePref);
|
||||
Services.prefs.clearUserPref(kApiKeyPref);
|
||||
Services.prefs.clearUserPref(kShowUIPref);
|
||||
});
|
||||
});
|
||||
|
||||
@ -45,6 +49,38 @@ add_task(function* test_yandex_translation() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* Ensure that Yandex.Translate is propertly attributed.
|
||||
*/
|
||||
add_task(function* test_yandex_attribution() {
|
||||
// Loading the fixture page.
|
||||
let url = constructFixtureURL("bug1022725-fr.html");
|
||||
let tab = yield promiseTestPageLoad(url);
|
||||
|
||||
info("Show an info bar saying the current page is in French");
|
||||
let notif = showTranslationUI(tab, "fr");
|
||||
let attribution = notif._getAnonElt("translationEngine").selectedIndex;
|
||||
Assert.equal(attribution, 1, "Yandex attribution should be shown.");
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
|
||||
add_task(function* test_preference_attribution() {
|
||||
|
||||
let prefUrl = "about:preferences#content";
|
||||
let tab = yield promiseTestPageLoad(prefUrl);
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
let win = browser.contentWindow;
|
||||
let bingAttribution = win.document.getElementById("bingAttribution");
|
||||
ok(bingAttribution, "Bing attribution should exist.");
|
||||
ok(bingAttribution.hidden, "Bing attribution should be hidden.");
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* A helper function for constructing a URL to a page stored in the
|
||||
* local fixture folder.
|
||||
@ -79,3 +115,12 @@ function promiseTestPageLoad(url) {
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function showTranslationUI(tab, aDetectedLanguage) {
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
Translation.documentStateReceived(browser, {state: Translation.STATE_OFFER,
|
||||
originalShown: true,
|
||||
detectedLanguage: aDetectedLanguage});
|
||||
let ui = browser.translationUI;
|
||||
return ui.notificationBox.getNotificationWithValue("translation");
|
||||
}
|
||||
|
@ -127,12 +127,17 @@
|
||||
<xul:menuitem oncommand="openPreferences('paneContent');"
|
||||
label="&translation.options.preferences.label;"
|
||||
accesskey="&translation.options.preferences.accesskey;"/>
|
||||
<xul:menuitem class="translation-attribution subviewbutton panel-subview-footer"
|
||||
<xul:menuitem class="subviewbutton panel-subview-footer"
|
||||
oncommand="document.getBindingParent(this).openProviderAttribution();">
|
||||
<xul:label>&translation.options.attribution.beforeLogo;</xul:label>
|
||||
<xul:image src="chrome://browser/content/microsoft-translator-attribution.png"
|
||||
aria-label="Microsoft Translator"/>
|
||||
<xul:label>&translation.options.attribution.afterLogo;</xul:label>
|
||||
<xul:deck anonid="translationEngine" selectedIndex="0">
|
||||
<xul:hbox class="translation-attribution">
|
||||
<xul:label>&translation.options.attribution.beforeLogo;</xul:label>
|
||||
<xul:image src="chrome://browser/content/microsoft-translator-attribution.png"
|
||||
aria-label="Microsoft Translator"/>
|
||||
<xul:label>&translation.options.attribution.afterLogo;</xul:label>
|
||||
</xul:hbox>
|
||||
<xul:label class="translation-attribution">&translation.options.attribution.yandexTranslate;</xul:label>
|
||||
</xul:deck>
|
||||
</xul:menuitem>
|
||||
</xul:menupopup>
|
||||
</xul:button>
|
||||
@ -215,6 +220,13 @@
|
||||
if (aTranslation.state)
|
||||
this.state = aTranslation.state;
|
||||
|
||||
// Show attribution for the preferred translator.
|
||||
let engineIndex = Object.keys(Translation.supportedEngines)
|
||||
.indexOf(Translation.translationEngine);
|
||||
if (engineIndex != -1) {
|
||||
this._getAnonElt('translationEngine').selectedIndex = engineIndex;
|
||||
}
|
||||
|
||||
const kWelcomePref = "browser.translation.ui.welcomeMessageShown";
|
||||
if (Services.prefs.prefHasUserValue(kWelcomePref) ||
|
||||
this.translation.browser != gBrowser.selectedBrowser)
|
||||
|
@ -64,3 +64,12 @@
|
||||
-->
|
||||
<!ENTITY translation.options.attribution.beforeLogo "Translations by">
|
||||
<!ENTITY translation.options.attribution.afterLogo "">
|
||||
|
||||
<!-- LOCALIZATION NOTE (translation.options.attribution.poweredByYandex,
|
||||
translation.options.attribution.beforeLogo,
|
||||
- translation.options.attribution.afterLogo):
|
||||
- translation.options.attribution.poweredByYandex is displayed instead of
|
||||
- the other two strings when yandex translation engine is preferred by the
|
||||
- user.
|
||||
-->
|
||||
<!ENTITY translation.options.attribution.yandexTranslate "Powered by Yandex.Translate">
|
||||
|
Loading…
Reference in New Issue
Block a user