MessageBundle
pentaho.i18n. MessageBundle
The MessageBundle
class is a container of localized messages.
Each localized message is accessible by a string key. Messages can have property tags in them, using the pattern:
"{0}"
, "{1}"
, ... or "{keyword0}"
, "{keyword1}"
, ...
AMD Module
require(["pentaho/i18n/MessageBundle"], function(MessageBundle) { /* code goes here */ });
Constructor
Name | Description |
---|---|
new MessageBundle(source) | Creates a message bundle given a messages dictionary. |
Members
Name | Description |
---|---|
format |
Methods
Name | Description |
---|---|
format(text, scope) : string Static | Formats a string by replacing the property tags it contains by their corresponding values in a scope. |
get(key, scope, missingMsg) : string | Gets a localized, formatted message, given its key. |
has(key) : boolean | Indicates if the bundle contains a message with the given key. |
Constructor Details
new MessageBundle(source) | ||||||
---|---|---|---|---|---|---|
Creates a message bundle given a messages dictionary. Source: javascript/web/pentaho/i18n/MessageBundle.js, line 23
|
Members Details
format: |
---|
Source: javascript/web/pentaho/i18n/MessageBundle.js, line 190 See also: pentaho.i18n.MessageBundle.format |
Methods Details
format(text, scope) : string Static | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Formats a string by replacing the property tags it contains by their corresponding values in a scope. Property tags have the format To represent a literal brace character, place two consecutive brace characters, When a property tag results in a nully value (like when Source: javascript/web/pentaho/i18n/MessageBundle.js, line 167
Example MessageBundle.format("text"); //returns "text" MessageBundle.format("text_{0}"); //returns "text_[?]" MessageBundle.format("text_{0}", ["v1"]); //returns "text_v1" MessageBundle.format("text_{k}", {"k": "v2"}); //returns "text_v2" MessageBundle.format("text_{v3}", function(p) { //returns "text_v3" return p; }); |
get(key, scope, missingMsg) : string | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gets a localized, formatted message, given its key. Source: javascript/web/pentaho/i18n/MessageBundle.js, line 87
Example define(["pentaho/i18n/MessageBundle"], function(MessageBundle) { var bundle = new MessageBundle({key1: "value1", key2: "value2_{0}", key3: "value3_{keyword}"); bundle.get("key1"); //returns "value1" bundle.get("keyNA", "default"); //returns "default" bundle.get("key2", ["scope"]); //returns "value2_first" bundle.get("key2", {"keyword": "scope2"}); //returns "value3_scope2" bundle.get("keyNA", ["scope"], "default"); //returns "default" bundle.get("key2", [], "default"); //returns "value2_[?]" }); |
has(key) : boolean | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Indicates if the bundle contains a message with the given key. Source: javascript/web/pentaho/i18n/MessageBundle.js, line 54
|