mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-07 12:15:51 +00:00
cc1047e2c3
--HG-- extra : rebase_source : 0d2c4d772a672a4b2f7db28ea5cf0905d58b03b1
358 lines
15 KiB
XML
358 lines
15 KiB
XML
<?xml version="1.0"?>
|
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
|
|
|
<!DOCTYPE bindings [
|
|
<!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd">
|
|
%notificationDTD;
|
|
<!ENTITY % translationDTD SYSTEM "chrome://browser/locale/translation.dtd" >
|
|
%translationDTD;
|
|
]>
|
|
|
|
<bindings id="translationBindings"
|
|
xmlns="http://www.mozilla.org/xbl"
|
|
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
xmlns:xbl="http://www.mozilla.org/xbl">
|
|
<binding id="translationbar" extends="chrome://global/content/bindings/notification.xml#notification" role="xul:alert">
|
|
<resources>
|
|
<stylesheet src="chrome://global/skin/notification.css"/>
|
|
</resources>
|
|
<content>
|
|
<xul:hbox class="notification-inner outset" flex="1" xbl:inherits="type">
|
|
<xul:hbox anonid="details" align="center" flex="1">
|
|
<xul:image class="translate-infobar-element messageImage"
|
|
anonid="messageImage"/>
|
|
<xul:deck anonid="translationStates" selectedIndex="0">
|
|
|
|
<!-- offer to translate -->
|
|
<xul:hbox class="translate-offer-box" align="center">
|
|
<xul:label class="translate-infobar-element" value="&translation.thisPageIsIn.label;"/>
|
|
<xul:menulist class="translate-infobar-element" anonid="detectedLanguage">
|
|
<xul:menupopup/>
|
|
</xul:menulist>
|
|
<xul:label class="translate-infobar-element" value="&translation.translateThisPage.label;"/>
|
|
<xul:button class="translate-infobar-element"
|
|
label="&translation.translate.button;"
|
|
anonid="translate"
|
|
oncommand="document.getBindingParent(this).translate();"/>
|
|
<xul:button class="translate-infobar-element"
|
|
label="&translation.notNow.button;" anonid="notNow"
|
|
oncommand="document.getBindingParent(this).closeCommand();"/>
|
|
</xul:hbox>
|
|
|
|
<!-- translating -->
|
|
<xul:vbox class="translating-box" pack="center">
|
|
<xul:label class="translate-infobar-element"
|
|
value="&translation.translatingContent.label;"/>
|
|
</xul:vbox>
|
|
|
|
<!-- translated -->
|
|
<xul:hbox class="translated-box" align="center">
|
|
<xul:label class="translate-infobar-element"
|
|
value="&translation.translatedFrom.label;"/>
|
|
<xul:menulist class="translate-infobar-element"
|
|
anonid="fromLanguage"
|
|
oncommand="document.getBindingParent(this).translate()">
|
|
<xul:menupopup/>
|
|
</xul:menulist>
|
|
<xul:label class="translate-infobar-element"
|
|
value="&translation.translatedTo.label;"/>
|
|
<xul:menulist class="translate-infobar-element"
|
|
anonid="toLanguage"
|
|
oncommand="document.getBindingParent(this).translate()">
|
|
<xul:menupopup/>
|
|
</xul:menulist>
|
|
<xul:label class="translate-infobar-element"
|
|
value="&translation.translatedToSuffix.label;"/>
|
|
<xul:button anonid="showOriginal"
|
|
class="translate-infobar-element"
|
|
label="&translation.showOriginal.button;"
|
|
oncommand="document.getBindingParent(this).showOriginal();"/>
|
|
<xul:button anonid="showTranslation"
|
|
class="translate-infobar-element"
|
|
label="&translation.showTranslation.button;"
|
|
oncommand="document.getBindingParent(this).showTranslation();"/>
|
|
</xul:hbox>
|
|
|
|
<!-- error -->
|
|
<xul:hbox class="translation-error" align="center">
|
|
<xul:label class="translate-infobar-element"
|
|
value="&translation.errorTranslating.label;"/>
|
|
<xul:button class="translate-infobar-element"
|
|
label="&translation.tryAgain.button;"
|
|
anonid="tryAgain"
|
|
oncommand="document.getBindingParent(this).translate();"/>
|
|
</xul:hbox>
|
|
|
|
<!-- unavailable -->
|
|
<xul:vbox class="translation-unavailable" pack="center">
|
|
<xul:label class="translate-infobar-element"
|
|
value="&translation.serviceUnavailable.label;"/>
|
|
</xul:vbox>
|
|
|
|
</xul:deck>
|
|
<xul:spacer flex="1"/>
|
|
|
|
<xul:button type="menu"
|
|
class="translate-infobar-element options-menu-button"
|
|
anonid="options"
|
|
label="&translation.options.menu;">
|
|
<xul:menupopup class="translation-menupopup cui-widget-panel cui-widget-panelview
|
|
cui-widget-panelWithFooter PanelUI-subView"
|
|
onpopupshowing="document.getBindingParent(this).optionsShowing();">
|
|
<xul:menuitem anonid="neverForLanguage"
|
|
oncommand="document.getBindingParent(this).neverForLanguage();"/>
|
|
<xul:menuitem anonid="neverForSite"
|
|
oncommand="document.getBindingParent(this).neverForSite();"
|
|
label="&translation.options.neverForSite.label;"
|
|
accesskey="&translation.options.neverForSite.accesskey;"/>
|
|
<xul:menuseparator/>
|
|
<xul:menuitem oncommand="openPreferences('paneContent');"
|
|
label="&translation.options.preferences.label;"
|
|
accesskey="&translation.options.preferences.accesskey;"/>
|
|
<xul:menuitem class="translation-attribution 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:menuitem>
|
|
</xul:menupopup>
|
|
</xul:button>
|
|
|
|
</xul:hbox>
|
|
<xul:toolbarbutton ondblclick="event.stopPropagation();"
|
|
anonid="closeButton"
|
|
class="messageCloseButton close-icon tabbable"
|
|
xbl:inherits="hidden=hideclose"
|
|
tooltiptext="&closeNotification.tooltip;"
|
|
oncommand="document.getBindingParent(this).closeCommand();"/>
|
|
</xul:hbox>
|
|
</content>
|
|
<implementation>
|
|
<property name="state"
|
|
onget="return this._getAnonElt('translationStates').selectedIndex;">
|
|
<setter>
|
|
<![CDATA[
|
|
let deck = this._getAnonElt('translationStates');
|
|
|
|
let activeElt = document.activeElement;
|
|
if (activeElt && deck.contains(activeElt))
|
|
activeElt.blur();
|
|
|
|
let stateName;
|
|
for (let name of ["OFFER", "TRANSLATING", "TRANSLATED", "ERROR"]) {
|
|
if (Translation["STATE_" + name] == val) {
|
|
stateName = name.toLowerCase();
|
|
break;
|
|
}
|
|
}
|
|
this.setAttribute("state", stateName);
|
|
|
|
if (val == Translation.STATE_TRANSLATED)
|
|
this._handleButtonHiding();
|
|
|
|
deck.selectedIndex = val;
|
|
]]>
|
|
</setter>
|
|
</property>
|
|
|
|
<method name="init">
|
|
<parameter name="aTranslation"/>
|
|
<body>
|
|
<![CDATA[
|
|
this.translation = aTranslation;
|
|
let bundle = Cc["@mozilla.org/intl/stringbundle;1"]
|
|
.getService(Ci.nsIStringBundleService)
|
|
.createBundle("chrome://global/locale/languageNames.properties");
|
|
let sortByLocalizedName = function(aList) {
|
|
return aList.map(code => [code, bundle.GetStringFromName(code)])
|
|
.sort((a, b) => a[1].localeCompare(b[1]));
|
|
};
|
|
|
|
// Fill the lists of supported source languages.
|
|
let detectedLanguage = this._getAnonElt("detectedLanguage");
|
|
let fromLanguage = this._getAnonElt("fromLanguage");
|
|
let sourceLanguages =
|
|
sortByLocalizedName(Translation.supportedSourceLanguages);
|
|
for (let [code, name] of sourceLanguages) {
|
|
detectedLanguage.appendItem(name, code);
|
|
fromLanguage.appendItem(name, code);
|
|
}
|
|
detectedLanguage.value = this.translation.detectedLanguage;
|
|
|
|
// translatedFrom is only set if we have already translated this page.
|
|
if (aTranslation.translatedFrom)
|
|
fromLanguage.value = aTranslation.translatedFrom;
|
|
|
|
// Fill the list of supported target languages.
|
|
let toLanguage = this._getAnonElt("toLanguage");
|
|
let targetLanguages =
|
|
sortByLocalizedName(Translation.supportedTargetLanguages);
|
|
for (let [code, name] of targetLanguages)
|
|
toLanguage.appendItem(name, code);
|
|
|
|
if (aTranslation.translatedTo)
|
|
toLanguage.value = aTranslation.translatedTo;
|
|
|
|
if (aTranslation.state)
|
|
this.state = aTranslation.state;
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="_getAnonElt">
|
|
<parameter name="aAnonId"/>
|
|
<body>
|
|
return document.getAnonymousElementByAttribute(this, "anonid", aAnonId);
|
|
</body>
|
|
</method>
|
|
|
|
<method name="translate">
|
|
<body>
|
|
<![CDATA[
|
|
if (this.state == Translation.STATE_OFFER) {
|
|
this._getAnonElt("fromLanguage").value =
|
|
this._getAnonElt("detectedLanguage").value;
|
|
this._getAnonElt("toLanguage").value =
|
|
Translation.defaultTargetLanguage;
|
|
}
|
|
|
|
this.translation.translate(this._getAnonElt("fromLanguage").value,
|
|
this._getAnonElt("toLanguage").value);
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<!-- To be called when the infobar should be closed per user's wish (e.g.
|
|
by clicking the notification's close button -->
|
|
<method name="closeCommand">
|
|
<body>
|
|
<![CDATA[
|
|
this.close();
|
|
this.translation.infobarClosed();
|
|
]]>
|
|
</body>
|
|
</method>
|
|
<method name="_handleButtonHiding">
|
|
<body>
|
|
<![CDATA[
|
|
let originalShown = this.translation.originalShown;
|
|
this._getAnonElt("showOriginal").hidden = originalShown;
|
|
this._getAnonElt("showTranslation").hidden = !originalShown;
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="showOriginal">
|
|
<body>
|
|
<![CDATA[
|
|
this.translation.showOriginalContent();
|
|
this._handleButtonHiding();
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="showTranslation">
|
|
<body>
|
|
<![CDATA[
|
|
this.translation.showTranslatedContent();
|
|
this._handleButtonHiding();
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="optionsShowing">
|
|
<body>
|
|
<![CDATA[
|
|
// Get the source language name.
|
|
let lang;
|
|
if (this.state == Translation.STATE_OFFER)
|
|
lang = this._getAnonElt("detectedLanguage").value;
|
|
else {
|
|
lang = this._getAnonElt("fromLanguage").value;
|
|
|
|
// If we have never attempted to translate the page before the
|
|
// service became unavailable, "fromLanguage" isn't set.
|
|
if (!lang && this.state == Translation.STATE_UNAVAILABLE)
|
|
lang = this.translation.detectedLanguage;
|
|
}
|
|
|
|
let langBundle =
|
|
Cc["@mozilla.org/intl/stringbundle;1"]
|
|
.getService(Ci.nsIStringBundleService)
|
|
.createBundle("chrome://global/locale/languageNames.properties");
|
|
let langName = langBundle.GetStringFromName(lang);
|
|
|
|
// Set the label and accesskey on the menuitem.
|
|
let bundle =
|
|
Cc["@mozilla.org/intl/stringbundle;1"]
|
|
.getService(Ci.nsIStringBundleService)
|
|
.createBundle("chrome://browser/locale/translation.properties");
|
|
let item = this._getAnonElt("neverForLanguage");
|
|
const kStrId = "translation.options.neverForLanguage";
|
|
item.setAttribute("label",
|
|
bundle.formatStringFromName(kStrId + ".label",
|
|
[langName], 1));
|
|
item.setAttribute("accesskey",
|
|
bundle.GetStringFromName(kStrId + ".accesskey"));
|
|
item.langCode = lang;
|
|
|
|
// We may need to disable the menuitems if they have already been used.
|
|
// Check if translation is already disabled for this language:
|
|
let neverForLangs =
|
|
Services.prefs.getCharPref("browser.translation.neverForLanguages");
|
|
item.disabled = neverForLangs.split(",").indexOf(lang) != -1;
|
|
|
|
// Check if translation is disabled for the domain:
|
|
let uri = this.translation.browser.currentURI;
|
|
let perms = Services.perms;
|
|
item = this._getAnonElt("neverForSite");
|
|
item.disabled =
|
|
perms.testExactPermission(uri, "translate") == perms.DENY_ACTION;
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="neverForLanguage">
|
|
<body>
|
|
<![CDATA[
|
|
const kPrefName = "browser.translation.neverForLanguages";
|
|
|
|
let val = Services.prefs.getCharPref(kPrefName);
|
|
if (val)
|
|
val += ",";
|
|
val += this._getAnonElt("neverForLanguage").langCode;
|
|
|
|
Services.prefs.setCharPref(kPrefName, val);
|
|
|
|
this.closeCommand();
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="neverForSite">
|
|
<body>
|
|
<![CDATA[
|
|
let uri = this.translation.browser.currentURI;
|
|
let perms = Services.perms;
|
|
perms.add(uri, "translate", perms.DENY_ACTION);
|
|
|
|
this.closeCommand();
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
<method name="openProviderAttribution">
|
|
<body>
|
|
<![CDATA[
|
|
Translation.openProviderAttribution();
|
|
]]>
|
|
</body>
|
|
</method>
|
|
|
|
</implementation>
|
|
</binding>
|
|
</bindings>
|