app-strings
The app-strings
module gives you access to the host application's localized
string bundles (.properties
files).
The module exports the StringBundle
constructor function. To access a string
bundle, construct an instance of StringBundle
, passing it the bundle's URL:
var StringBundle = require("app-strings").StringBundle;
var bundle = StringBundle("chrome://browser/locale/browser.properties");
To get the value of a string, call the object's get
method, passing it
the name of the string:
var accessKey = bundle.get("contextMenuSearchText.accesskey");
// "S" in the en-US locale
To get the formatted value of a string that accepts arguments, call the object's
get
method, passing it the name of the string and an array of arguments
with which to format the string:
var searchText = bundle.get("contextMenuSearchText",
["universe", "signs of intelligent life"]);
// 'Search universe for "signs of intelligent life"' in the en-US locale
To get all strings in the bundle, iterate the object, which returns arrays of the form [name, value]:
for (var [name, value] in Iterator(bundle))
console.log(name + " = " + value);
Iteration
for (var name in bundle) { ... }
Iterate the names of strings in the bundle.
for each (var val in bundle) { ... }
Iterate the values of strings in the bundle.
for (var [name, value] in Iterator(bundle)) { ... }
Iterate the names and values of strings in the bundle.
API Reference
Classes
StringBundle
The StringBundle
object represents a string bundle.
Constructors
StringBundle(url)
Creates a StringBundle object that gives you access to a string bundle.
url : string
the URL of the string bundle
Returns: StringBundle
the string bundle
Methods
get(name, args)
Get the value of the string with the given name.
[ name : string ]
the name of the string to get
[ args : array ]
(optional) strings that replace placeholders in the string
Returns: string
the value of the string