toolkit/content/widgets/stringbundle.xml

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:aac56c8fe332
1 <?xml version="1.0"?>
2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
3 - License, v. 2.0. If a copy of the MPL was not distributed with this
4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5
6
7 <bindings id="stringBundleBindings"
8 xmlns="http://www.mozilla.org/xbl"
9 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10
11 <binding id="stringbundleset" extends="xul:box"/>
12
13 <binding id="stringbundle" extends="xul:spacer">
14 <implementation name="XStringBundle">
15
16 <method name="getString">
17 <parameter name="aStringKey"/>
18 <body>
19 <![CDATA[
20 try {
21 return this.stringBundle.GetStringFromName(aStringKey);
22 }
23 catch (e) {
24 dump("*** Failed to get string " + aStringKey + " in bundle: " + this.src + "\n");
25 throw e;
26 }
27 ]]>
28 </body>
29 </method>
30
31 <method name="getFormattedString">
32 <parameter name="aStringKey"/>
33 <parameter name="aStringsArray"/>
34 <body>
35 <![CDATA[
36 try {
37 return this.stringBundle.formatStringFromName(aStringKey, aStringsArray, aStringsArray.length);
38 }
39 catch (e) {
40 dump("*** Failed to format string " + aStringKey + " in bundle: " + this.src + "\n");
41 throw e;
42 }
43 ]]>
44 </body>
45 </method>
46
47 <property name="stringBundle" readonly="true">
48 <getter>
49 <![CDATA[
50 if (!this._bundle) {
51 try {
52 this._bundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
53 .getService(Components.interfaces.nsIStringBundleService)
54 .createBundle(this.src);
55 }
56 catch (e) {
57 dump("Failed to get stringbundle:\n");
58 dump(e + "\n");
59 }
60 }
61 return this._bundle;
62 ]]>
63 </getter>
64 </property>
65
66 <property name="src">
67 <getter>
68 <![CDATA[
69 return this.getAttribute("src");
70 ]]>
71 </getter>
72 <setter>
73 <![CDATA[
74 this._bundle = null;
75 this.setAttribute("src", val);
76 return val;
77 ]]>
78 </setter>
79 </property>
80
81 <property name="strings">
82 <getter>
83 <![CDATA[
84 // Note: this is a sucky method name! Should be:
85 // readonly attribute nsISimpleEnumerator strings;
86 return this.stringBundle.getSimpleEnumeration();
87 ]]>
88 </getter>
89 </property>
90
91 <field name="_bundle">null</field>
92
93 </implementation>
94 </binding>
95
96 </bindings>

mercurial