Class: Lexicon

nmodule/js/rc/lex/lex~ Lexicon


new Lexicon(moduleName, data)

A Lexicon is a map of locale specific name/value pairs for a module.

An instance of a Lexicon can be accessed indirectly by use of the
module method.

Parameters:
Name Type Description
moduleName String

The name of the Niagara Module this Lexicon relates too.

data Object

An object contained key values pairs for the Lexicon.

Example

Access a module's Lexicon

lexjs.module("js")
       .then(function (lex) {
         console.log("Some text from a lexicon: " + lex.get("dialogs.ok"));
       });

Methods


get(obj)

Return a value from the Lexicon for a given key.

The argument for this method can be either a String key followed by arguments or an Object Literal.

Parameters:
Name Type Description
obj Object | String

the Object Literal that contains the method's arguments or a String key.

Properties
Name Type Description
key String

the key to look up.

def String

the default value to return if the key can't be found.
By default this is null.

args Array | String

arguments used for String formatting. If the first parameter
is a String key, this list can just be further arguments for the function.

Returns:

the value for the Lexicon or return def if can't be found.

Type
String
Examples

Access a Lexicon value via its key name.

lexjs.module("js")
       .then(function (lex) {
         console.log(lex.get("dialogs.ok"));
       });
       

Access a Lexicon value via its key name with some formatted parameters.

lexjs.module("bajaui")
       .then(function (lex) {
          var val = lex.get("fileSearch.scanningFiles", "alpha", "omega"))
          // Prints out: Scanning files (found alpha of omega)...
          console.log(val);
       })); 
       

Provide a default value if the key can't be found and use an Object Literal instead

lexjs.module("bajaui")
       .then(function (lex) {
         // Use an Object Literal instead of multiple arguments and provide a default value.
         var val = lex.get({
           key: "fileSearch.scanningFiles",
           def: "Return this if the key can't be found in the Lexicon",
           args: ["alpha", "omega"]
         });
         console.log(val);
       });

getModuleName()

Return the Lexicon's module name.

Returns:
Type
String
Example

Return a Lexicon's module name

lexjs.module("bajaui")
       .then(function (lex) {
          // Prints out: bajaui
          console.log(lex.getModuleName());
       }));