using the string bundle service
The second way to access string bundles is to call the string bundle service directly from JavaScript
(the string bundle doesn't have to be refrenced in the XUL file, and stays outside the DOM tree):
Sample XUL: openLocation.xul, calling some JS code
<?xml version="1.0"?>
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/openLocation.dtd">
<dialog id="openLocation" ... title="&caption.label;" onLoad="onLoad();">
<script type="application/x-javascript" src="chrome://communicator/content/openLocation.js"/>
...
<menuitem value="0" id="currentWindow" label="&topWindow.label;"/>
...
</dialog>
Sample JavaScript: openLocation.js
...
function onLoad()
{
dialog.main = document.getElementById("openLocation");
dialog.openTopWindow = document.getElementById("currentWindow");
var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
var brandbundle = strBundleService.createBundle("chrome://global/locale/brand.properties");
var dialogbundle = strBundleService.createBundle("chrome://communicator/locale/openLocation.properties");
if (!browser) {
// No browser supplied - we are calling from Composer
// Change string to make more sense for Composer
dialog.openTopWindow.setAttribute("label", dialogbundle.GetStringFromName("existingNavigatorWindow"));
// change title to 'Open Location with Mozilla'
var brandShortName = brandbundle.GetStringFromName("brandShortName");
dialog.open.setAttribute("title", dialogbundle.getFormattedString("caption2.label", brandShortName));
}
}
Sample string bundle: openLocation.properties
existingNavigatorWindow=Existing Navigator window
caption2.label=Open Location with %S
Sample string bundle: brand.properties
brandShortName=Mozilla