Skip to main content

Pentaho+ documentation has moved!

The new product documentation portal is here. Check it out now at docs.hitachivantara.com

 

Hitachi Vantara Lumada and Pentaho Documentation

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

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

Parameters:
Name Default Value Summary
source : Object.<stringstring>
Optional

A messages dictionary.

Members Details

format:

Source: javascript/web/pentaho/i18n/MessageBundle.js, line 190

See also: pentaho.i18n.MessageBundle.format

Methods Details

format(text, scope) : string

Formats a string by replacing the property tags it contains by their corresponding values in a scope.

Property tags have the format "{property}", where property can be a number or a word that does not contain the special "{" and "}" characters.

To represent a literal brace character, place two consecutive brace characters, "{{" or "}}".

When a property tag results in a nully value (like when scope is not specified), it is replaced by the special marker "[?]".

Source: javascript/web/pentaho/i18n/MessageBundle.js, line 167

Parameters:
Name Default Value Summary
text : string

The text to format.

scope : Array | Object | function
Optional

A scope array, object or function.

Returns:
Name Description
string

The formatted string.

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

Parameters:
Name Default Value Summary
key : string

The message key.

scope : Array | Object | function
Optional

A scope array, object or function. This parameter can be specified nully or totally omitted.

missingMsg : string
Optional

The text to return when a message with the specified key is not defined. When undefined, the missing message is the specified key. When null (and three arguments were specified), the missing message is null.

Returns:
Name Description
string

A formatted message.

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

Parameters:
Name Default Value Summary
key : string

The key of the message.

Returns:
Name Description
boolean

true if yes, false if no.