1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/widgets/stringbundle.xml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 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 + 1.10 +<bindings id="stringBundleBindings" 1.11 + xmlns="http://www.mozilla.org/xbl" 1.12 + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.13 + 1.14 + <binding id="stringbundleset" extends="xul:box"/> 1.15 + 1.16 + <binding id="stringbundle" extends="xul:spacer"> 1.17 + <implementation name="XStringBundle"> 1.18 + 1.19 + <method name="getString"> 1.20 + <parameter name="aStringKey"/> 1.21 + <body> 1.22 + <![CDATA[ 1.23 + try { 1.24 + return this.stringBundle.GetStringFromName(aStringKey); 1.25 + } 1.26 + catch (e) { 1.27 + dump("*** Failed to get string " + aStringKey + " in bundle: " + this.src + "\n"); 1.28 + throw e; 1.29 + } 1.30 + ]]> 1.31 + </body> 1.32 + </method> 1.33 + 1.34 + <method name="getFormattedString"> 1.35 + <parameter name="aStringKey"/> 1.36 + <parameter name="aStringsArray"/> 1.37 + <body> 1.38 + <![CDATA[ 1.39 + try { 1.40 + return this.stringBundle.formatStringFromName(aStringKey, aStringsArray, aStringsArray.length); 1.41 + } 1.42 + catch (e) { 1.43 + dump("*** Failed to format string " + aStringKey + " in bundle: " + this.src + "\n"); 1.44 + throw e; 1.45 + } 1.46 + ]]> 1.47 + </body> 1.48 + </method> 1.49 + 1.50 + <property name="stringBundle" readonly="true"> 1.51 + <getter> 1.52 + <![CDATA[ 1.53 + if (!this._bundle) { 1.54 + try { 1.55 + this._bundle = Components.classes["@mozilla.org/intl/stringbundle;1"] 1.56 + .getService(Components.interfaces.nsIStringBundleService) 1.57 + .createBundle(this.src); 1.58 + } 1.59 + catch (e) { 1.60 + dump("Failed to get stringbundle:\n"); 1.61 + dump(e + "\n"); 1.62 + } 1.63 + } 1.64 + return this._bundle; 1.65 + ]]> 1.66 + </getter> 1.67 + </property> 1.68 + 1.69 + <property name="src"> 1.70 + <getter> 1.71 + <![CDATA[ 1.72 + return this.getAttribute("src"); 1.73 + ]]> 1.74 + </getter> 1.75 + <setter> 1.76 + <![CDATA[ 1.77 + this._bundle = null; 1.78 + this.setAttribute("src", val); 1.79 + return val; 1.80 + ]]> 1.81 + </setter> 1.82 + </property> 1.83 + 1.84 + <property name="strings"> 1.85 + <getter> 1.86 + <![CDATA[ 1.87 + // Note: this is a sucky method name! Should be: 1.88 + // readonly attribute nsISimpleEnumerator strings; 1.89 + return this.stringBundle.getSimpleEnumeration(); 1.90 + ]]> 1.91 + </getter> 1.92 + </property> 1.93 + 1.94 + <field name="_bundle">null</field> 1.95 + 1.96 + </implementation> 1.97 + </binding> 1.98 + 1.99 +</bindings>