1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/translation/translation-infobar.xml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,186 @@ 1.4 +<?xml version="1.0"?> 1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.6 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.8 + 1.9 +<!DOCTYPE bindings [ 1.10 +<!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd"> 1.11 +%notificationDTD; 1.12 +<!ENTITY % translationDTD SYSTEM "chrome://browser/locale/translation.dtd" > 1.13 +%translationDTD; 1.14 +]> 1.15 + 1.16 +<bindings id="translationBindings" 1.17 + xmlns="http://www.mozilla.org/xbl" 1.18 + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.19 + xmlns:xbl="http://www.mozilla.org/xbl"> 1.20 + <binding id="translationbar" extends="chrome://global/content/bindings/notification.xml#notification" role="xul:alert"> 1.21 + <resources> 1.22 + <stylesheet src="chrome://global/skin/notification.css"/> 1.23 + </resources> 1.24 + <content> 1.25 + <xul:hbox class="notification-inner outset" flex="1" xbl:inherits="type"> 1.26 + <xul:hbox anonid="details" align="center" flex="1"> 1.27 + <xul:image anonid="messageImage" class="messageImage" xbl:inherits="src=image,type,value"/> 1.28 + <xul:deck anonid="translationStates" selectedIndex="0"> 1.29 + 1.30 + <!-- offer to translate --> 1.31 + <xul:hbox class="translate-offer-box" align="baseline"> 1.32 + <xul:label value="&translation.thisPageIsIn.label;"/> 1.33 + <xul:menulist anonid="detectedLanguage"> 1.34 + <xul:menupopup/> 1.35 + </xul:menulist> 1.36 + <xul:label value="&translation.translateThisPage.label;"/> 1.37 + <xul:button label="&translation.translate.button;" anonid="translate" 1.38 + oncommand="document.getBindingParent(this).translate();"/> 1.39 + <xul:button label="&translation.notNow.button;" anonid="notNow" 1.40 + oncommand="document.getBindingParent(this).close();"/> 1.41 + </xul:hbox> 1.42 + 1.43 + <!-- translating --> 1.44 + <xul:vbox class="translating-box" pack="center"> 1.45 + <xul:label value="&translation.translatingContent.label;"/> 1.46 + </xul:vbox> 1.47 + 1.48 + <!-- translated --> 1.49 + <xul:hbox class="translated-box" align="baseline"> 1.50 + <xul:label value="&translation.translatedFrom.label;"/> 1.51 + <xul:menulist anonid="fromLanguage" 1.52 + oncommand="document.getBindingParent(this).translate()"> 1.53 + <xul:menupopup/> 1.54 + </xul:menulist> 1.55 + <xul:label value="&translation.translatedTo.label;"/> 1.56 + <xul:menulist anonid="toLanguage" 1.57 + oncommand="document.getBindingParent(this).translate()"> 1.58 + <xul:menupopup/> 1.59 + </xul:menulist> 1.60 + <xul:label value="&translation.translatedToSuffix.label;"/> 1.61 + <xul:button anonid="showOriginal" 1.62 + label="&translation.showOriginal.button;" 1.63 + oncommand="document.getBindingParent(this).showOriginal();"/> 1.64 + <xul:button anonid="showTranslation" 1.65 + label="&translation.showTranslation.button;" 1.66 + oncommand="document.getBindingParent(this).showTranslation();"/> 1.67 + </xul:hbox> 1.68 + 1.69 + <!-- error --> 1.70 + <xul:hbox class="translation-error" align="baseline"> 1.71 + <xul:label value="&translation.errorTranslating.label;"/> 1.72 + <xul:button label="&translation.tryAgain.button;" anonid="tryAgain" 1.73 + oncommand="document.getBindingParent(this).translate();"/> 1.74 + </xul:hbox> 1.75 + 1.76 + </xul:deck> 1.77 + <xul:spacer flex="1"/> 1.78 + 1.79 + <xul:button type="menu" label="&translation.options.menu;"> 1.80 + <xul:menupopup/> 1.81 + </xul:button> 1.82 + 1.83 + </xul:hbox> 1.84 + <xul:toolbarbutton ondblclick="event.stopPropagation();" 1.85 + class="messageCloseButton close-icon tabbable" 1.86 + xbl:inherits="hidden=hideclose" 1.87 + tooltiptext="&closeNotification.tooltip;" 1.88 + oncommand="document.getBindingParent(this).close();"/> 1.89 + </xul:hbox> 1.90 + </content> 1.91 + <implementation> 1.92 + <property name="state" 1.93 + onget="return this._getAnonElt('translationStates').selectedIndex;" 1.94 + onset="this._getAnonElt('translationStates').selectedIndex = val;"/> 1.95 + 1.96 + <method name="init"> 1.97 + <parameter name="aTranslation"/> 1.98 + <body> 1.99 + <![CDATA[ 1.100 + this.translation = aTranslation; 1.101 + let bundle = Cc["@mozilla.org/intl/stringbundle;1"] 1.102 + .getService(Ci.nsIStringBundleService) 1.103 + .createBundle("chrome://global/locale/languageNames.properties"); 1.104 + 1.105 + // Fill the lists of supported source languages. 1.106 + let detectedLanguage = this._getAnonElt("detectedLanguage"); 1.107 + let fromLanguage = this._getAnonElt("fromLanguage"); 1.108 + for (let code of Translation.supportedSourceLanguages) { 1.109 + let name = bundle.GetStringFromName(code); 1.110 + detectedLanguage.appendItem(name, code); 1.111 + fromLanguage.appendItem(name, code); 1.112 + } 1.113 + detectedLanguage.value = this.translation.detectedLanguage; 1.114 + 1.115 + // translatedFrom is only set if we have already translated this page. 1.116 + if (aTranslation.translatedFrom) 1.117 + fromLanguage.value = aTranslation.translatedFrom; 1.118 + 1.119 + // Fill the list of supporter target languages. 1.120 + let toLanguage = this._getAnonElt("toLanguage"); 1.121 + for (let code of Translation.supportedTargetLanguages) 1.122 + toLanguage.appendItem(bundle.GetStringFromName(code), code); 1.123 + 1.124 + if (aTranslation.translatedTo) 1.125 + toLanguage.value = aTranslation.translatedTo; 1.126 + 1.127 + if (aTranslation.state) 1.128 + this.state = aTranslation.state; 1.129 + 1.130 + this._handleButtonHiding(aTranslation.originalShown); 1.131 + ]]> 1.132 + </body> 1.133 + </method> 1.134 + 1.135 + <method name="_getAnonElt"> 1.136 + <parameter name="aAnonId"/> 1.137 + <body> 1.138 + return document.getAnonymousElementByAttribute(this, "anonid", aAnonId); 1.139 + </body> 1.140 + </method> 1.141 + 1.142 + <method name="translate"> 1.143 + <body> 1.144 + <![CDATA[ 1.145 + if (this.state == this.translation.STATE_OFFER) { 1.146 + this._getAnonElt("fromLanguage").value = 1.147 + this._getAnonElt("detectedLanguage").value; 1.148 + this._getAnonElt("toLanguage").value = 1.149 + Translation.defaultTargetLanguage; 1.150 + } 1.151 + 1.152 + this._handleButtonHiding(false); 1.153 + this.translation.translate(this._getAnonElt("fromLanguage").value, 1.154 + this._getAnonElt("toLanguage").value); 1.155 + ]]> 1.156 + </body> 1.157 + </method> 1.158 + 1.159 + <method name="_handleButtonHiding"> 1.160 + <parameter name="aOriginalShown"/> 1.161 + <body> 1.162 + <![CDATA[ 1.163 + this._getAnonElt("showOriginal").hidden = aOriginalShown; 1.164 + this._getAnonElt("showTranslation").hidden = !aOriginalShown; 1.165 + ]]> 1.166 + </body> 1.167 + </method> 1.168 + 1.169 + <method name="showOriginal"> 1.170 + <body> 1.171 + <![CDATA[ 1.172 + this._handleButtonHiding(true); 1.173 + this.translation.showOriginalContent(); 1.174 + ]]> 1.175 + </body> 1.176 + </method> 1.177 + 1.178 + <method name="showTranslation"> 1.179 + <body> 1.180 + <![CDATA[ 1.181 + this._handleButtonHiding(false); 1.182 + this.translation.showTranslatedContent(); 1.183 + ]]> 1.184 + </body> 1.185 + </method> 1.186 + 1.187 + </implementation> 1.188 + </binding> 1.189 +</bindings>