A JavaScript library used to access translated Lexicon values from the Niagara
Framework.
This library will make network calls back to a Web Server to access translated
values.
Attempts will also be made to use local storage to cache recorded Lexicon
values. If a user logs on with a different locale or the registry has been updated,
this storage will be automatically cleared.
Please try out the examples from the BajauxExamples
folder available from thedocDeveloper
palette to see how this gets used. Also there are some more code
examples embedded into the method comments below.
RequireJS configuration options can be specified for this library...
- noStorage: if truthy, no attempt at using storage will be used.
- forceInit: if truthy, an 'init' network call will be always be made
the first time this library loads. - lang: if specified, the user locale for the Lexicons. If this
isn't specified the library will make a network call
for it when it first loads. - storageId: if specified, the id that helps determine whether
the storage database currently being used is out of date.
This library is designed to be used through the RequireJS Lexicon plugin...
- Version:
-
- 0.0.1
- See:
Examples
Access the Lexicon JS library using RequireJS.
require(["lex!"], function (lexjs) { lexjs.module("js") .then(function (lex) { console.log("The Dialog OK button text: " + lex.get("dialogs.ok")); }); });
Directly access a module's Lexicon using the plug-in syntax for RequireJS
require(["lex!js,bajaui"], function (lexicons) { // The lexicon's array holds the Lexicon for both the js and bajaui modules. console.log("The Dialog OK button text: " + lexicons[0].get("dialogs.ok")); });
Requires
- module:Promise,
Classes
Methods
-
<static> format(str)
-
Asynchronously format a String using Niagara's BFormat conventions.
Parameters:
Name Type Description str
String the string that contains the BFormat style text
to use. The syntax should be%lexicon(moduleName:keyName)%
or%lexicon(moduleName:keyName:formatString1:formatString2)%
.Returns:
- Type
- Promise
Example
lexjs.format("%lexicon(bajaui:dialog.ok)% and %lexicon(bajaui:menu.new.label)%") .then(function (str) { // Prints: "OK and New" console.log(str); }); lexjs.format("%lexicon(bajaui:fileSearch.scanningFiles:arg1:arg2)%") .then(function (str) { // Prints: "Scanning files (found arg1 of arg2)..." console.log(str); });
-
<static> getLexiconFromCache(moduleName)
-
If the Lexicon is loaded and cached then return it. Otherwise return null.
Please note, this will not result in any network calls.Parameters:
Name Type Description moduleName
String The name of the module.
Returns:
The Lexicon or null if it can't be found.
- Type
- Lexicon
-
<static> module(moduleName)
-
Asynchronously resolve a Lexicon via module name. A promise is returned and resolved once
Lexicon has been found. If the Lexicon can't be found or there's a network error,
the promise will reject.Parameters:
Name Type Description moduleName
String the name of the module being requested.
Returns:
- Type
- Promise
Example
Access a Lexicon via its module name
lexjs.module("myModule") .then(function (lex) { // Access the Lexicon entry called 'foo' from 'myModule' console.log(lex.get("foo")); });