| 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 | <?xml version="1.0"?> |
| 29 | <br><!DOCTYPE dialog SYSTEM "chrome://communicator/locale/openLocation.dtd"> |
| 30 | <br><dialog id="openLocation" ... title="&caption.label;" onLoad="onLoad();"> |
| 31 | <br><script type="application/x-javascript" src="chrome://communicator/content/openLocation.js"/> |
| 32 | <br>... |
| 33 | <br> <menuitem value="0" id="currentWindow" label="&topWindow.label;"/> |
| 34 | <br>... |
| 35 | <br></dialog> |
| 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> dialog.main = document.getElementById("openLocation"); |
| 46 | <br> dialog.openTopWindow = document.getElementById("currentWindow"); |
| 47 | <br> var <b>strBundleService</b> = Components.classes["@mozilla.org/intl/stringbundle;1"]<b>.getService</b>(Components.interfaces.nsIStringBundleService); |
| 48 | <br> var brandbundle = strBundleService<b>.createBundle</b>("chrome://global/locale/brand.properties"); |
| 49 | <br> var dialogbundle = strBundleService<b>.createBundle</b>("chrome://communicator/locale/openLocation.properties"); |
| 50 | <br> if (!browser) { |
| 51 | <br> // No browser supplied - we are calling from Composer |
| 52 | <br> // Change string to make more sense for Composer |
| 53 | <br> dialog.openTopWindow.setAttribute("label", <b>dialogbundle.GetStringFromName</b>("<span class="hilite">existingNavigatorWindow</span>")); |
| 54 | <br> // change title to 'Open Location with Mozilla' |
| 55 | <br> var brandShortName = brandbundle.GetStringFromName("<span class="hilite">brandShortName</span>"); |
| 56 | <br> dialog.open.setAttribute("title", <b>dialogbundle.getFormattedString</b>("<span class="hilite">caption2.label</span>", brandShortName)); |
| 57 | <br> } |
| 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> |