add error page
[slides.git] / fosdem2003 / l10ntalk_07.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
5   <meta name="Author" content="KaiRo - Robert Kaiser">
6   <title>L10n talk - FOSDEM 2003 - Mozilla Meeting</title>
7   <link rel="stylesheet" type="text/css" href="l10ntalk.css">
8   <link rel="contents" href="index.html" title="Contents">
9   <link rel="index" href="l10ntalk_overview.html" title="Overview">
10   <link rel="start" href="index.html" title="Start">
11   <link rel="first" href="l10ntalk_01.html" title="First page">
12   <link rel="previous" href="l10ntalk_06.html" title="Previous page">
13   <link rel="next" href="l10ntalk_08.html" title="Next page">
14   <link rel="last" href="l10ntalk_12.html" title="Last page">
15 </head>
16 <body>
17
18 <h1>using the string bundle service</h1>
19
20 <div class="explanation">
21 The second way to access string bundles is to call the <b>string bundle service</b> directly from JavaScript
22 (the string bundle doesn't have to be refrenced in the XUL file, and stays outside the DOM tree):
23 </div>
24
25 <div class="sample">
26 <p class="sampledesc">Sample XUL: openLocation.xul, calling some JS code</p>
27 <div class="samplecontent">
28 &lt;?xml version=&quot;1.0&quot;?&gt;
29 <br>&lt;!DOCTYPE dialog SYSTEM &quot;chrome://communicator/locale/openLocation.dtd&quot;&gt;
30 <br>&lt;dialog id=&quot;openLocation&quot; ... title=&quot;&amp;caption.label;&quot; onLoad=&quot;onLoad();&quot;&gt;
31 <br>&lt;script type=&quot;application/x-javascript&quot; src=&quot;chrome://communicator/content/openLocation.js&quot;/&gt;
32 <br>...
33 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;menuitem value=&quot;0&quot; id=&quot;currentWindow&quot; label=&quot;&amp;topWindow.label;&quot;/&gt;
34 <br>...
35 <br>&lt;/dialog&gt;
36 </div>
37 </div>
38
39 <div class="sample">
40 <p class="sampledesc">Sample JavaScript: openLocation.js</p>
41 <div class="samplecontent">
42 ...
43 <br>function onLoad()
44 <br>{
45 <br>&nbsp;&nbsp;dialog.main = document.getElementById("openLocation");
46 <br>&nbsp;&nbsp;dialog.openTopWindow = document.getElementById("currentWindow");
47 <br>&nbsp;&nbsp;var <b>strBundleService</b> = Components.classes["@mozilla.org/intl/stringbundle;1"]<b>.getService</b>(Components.interfaces.nsIStringBundleService);
48 <br>&nbsp;&nbsp;var brandbundle = strBundleService<b>.createBundle</b>("chrome://global/locale/brand.properties");
49 <br>&nbsp;&nbsp;var dialogbundle = strBundleService<b>.createBundle</b>("chrome://communicator/locale/openLocation.properties");
50 <br>&nbsp;&nbsp;if (!browser) {
51 <br>&nbsp;&nbsp;&nbsp;&nbsp;// No browser supplied - we are calling from Composer
52 <br>&nbsp;&nbsp;&nbsp;&nbsp;// Change string to make more sense for Composer
53 <br>&nbsp;&nbsp;&nbsp;&nbsp;dialog.openTopWindow.setAttribute("label", <b>dialogbundle.GetStringFromName</b>("<span class="hilite">existingNavigatorWindow</span>"));
54 <br>&nbsp;&nbsp;&nbsp;&nbsp;// change title to 'Open Location with Mozilla'
55 <br>&nbsp;&nbsp;&nbsp;&nbsp;var brandShortName = brandbundle.GetStringFromName("<span class="hilite">brandShortName</span>");
56 <br>&nbsp;&nbsp;&nbsp;&nbsp;dialog.open.setAttribute("title", <b>dialogbundle.getFormattedString</b>("<span class="hilite">caption2.label</span>", brandShortName));
57 <br>&nbsp;&nbsp;}
58 <br>}
59 </div>
60 </div>
61
62 <div class="sample">
63 <p class="sampledesc">Sample string bundle: openLocation.properties</p>
64 <div class="samplecontent">
65 <span class="hilite">existingNavigatorWindow</span>=Existing Navigator window
66 <br><span class="hilite">caption2.label</span>=Open Location with %S
67 </div>
68 </div>
69
70 <div class="sample">
71 <p class="sampledesc">Sample string bundle: brand.properties</p>
72 <div class="samplecontent">
73 <span class="hilite">brandShortName</span>=Mozilla
74 </div>
75 </div>
76
77 </body>
78 </html>