Access StringBundle from Overlay

Stringbundles are handy for localizing your project by removing all of your strings into a separate, easy to access text file. Unfortunately adding the bundles into Thunderbird isn't as easy as adding them to your XUL overlay. The most efficient way to append these strings is by attaching them to an existing stringbundleset as such:

<stringbundleset id="stringbundleset">
  <stringbundle src="chrome://your_extension/locale/overlay.properties" id="your-extension-strings" /> 
</stringbundleset>

Now that your stringbundle is attached you can access it from JavaScript as follows:

var str = document.getElementById("your-extension-strings"); //get the stringbundle object itself 
str.getString("propertyName");                                 //get a string (and do something with it) 

 

Alternative way

let stringBundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
let bundle = stringBundleService.createBundle("chrome://your_extension/locale/overlay.properties");
let str = bundle.GetStringFromName("propertyName");

see nsIStringBundleService

Document Tags and Contributors

Contributors to this page: wbamberg
Last updated by: wbamberg,