Constructors
Methods
-
contains(key){Boolean}
-
Name Type Description key
String the key of the message
Returns:
Type Description Boolean true
if the messages contains the key,false
otherwiseExample
// EXAMPLE MESSAGES FILE "customMessages.properties" // myButton=My button // unitprice=The unitprice var i18nContext = documentsContext.getI18nContext(); var messages = i18nContext.getMessages("customMessages"); messages.contains("myButton"); // -> true messages.contains("myOtherButton"); // -> false
-
get(key, defaultValue, placeholder){String}
-
Returns the value for the given key, if the key is not found the defaultValue will be returned.
The method will try to replace placeholders ( {x} ) in the return value.Name Type Description key
String the key of the message
defaultValue
String optional return value if the key doesn't match any key in the properties file, must be set if placeholders are used
placeholder
string | Array.<string> optional replaces {x} tags inside the value, x is an integer greater than 0.
Can be any amount of strings or an array of strings.Returns:
Type Description String the message value Example
// EXAMPLE MESSAGES FILE "customMessages.properties" // myMessage=My message {1} {2} var i18nContext = documentsContext.getI18nContext(); var messages = i18nContext.getMessages("customMessages"); messages.get("myMessage"); // -> "My message {1} {2}" messages.get("myOtherMessage", "DefaultMessage"); // -> "DefaultMessage" messages.get("myMessage", null, " Placeholder1", " Placeholder2"); // -> "My message Placeholder1 Placeholder2" messages.get("myMessage", null, ["Placeholder1", "Placeholder2"]); // -> "My message Placeholder1 Placeholder2" messages.get("myMessage", null, "Placeholder2", "Placeholder1"); // -> "My message Placeholder2 Placeholder1"
-
keys(){Array.<string>}
-
Returns all the keys of the messages.
Returns:
Type Description Array.<string> the message keys Example
// EXAMPLE MESSAGES FILE "customMessages.properties" // myButton=My button // unitprice=The unitprice var i18nContext = documentsContext.getI18nContext(); var messages = i18nContext.getMessages("customMessages"); messages.keys(); // -> ["myButton", "unitprice"]