Access StringBundle from Overlay

Table of contents

  1. 1. Alternative way
Table of contents
  1. 1. Alternative way

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/" id="your-extension-strings" /> 

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[";1"].getService(Ci.nsIStringBundleService);
let bundle = stringBundleService.createBundle("chrome://your_extension/locale/");
let str = bundle.GetStringFromName("propertyName");

see nsIStringBundleService

Tags (1)

Edit tags

Attachments (0)


Attach file