dw.web
Class Resource
dw.web.Resource
Library class which provides methods for retrieving messages from properties
resource bundles which contain locale-specific strings. When your program
needs a locale-specific String, it loads it from the resource bundle that is
appropriate for the user's current locale. In this way, the program code is
largely independent of the user's locale.
In Commerce Cloud Digital, resources are associated with the templates of a cartridge.
These bundles consist of properties files with a common name defined in the
template/resources directory of a site cartridge. For example:
- templates/resources/message.properties
- templates/resources/message_en.properties
- templates/resources/message_en_US.properties
- templates/resources/message_de_DE.properties
Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Method Summary
static msg(key
:
String)
:
String
Returns the message from the default properties resource bundle (base name "message") corresponding to the specified key and the request locale.
static msg(key
:
String, defaultMessage
:
String)
:
String
Returns the message from the default properties resource bundle (base name "message") corresponding to the specified key and the request locale.
Methods inherited from class
Object
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
Method Detail
msg
Returns the message from the default properties resource bundle (base
name "message") corresponding to the specified key and the request
locale.
This method is equivalent to msg(String, null).
Parameters:
key
-
resource bundle message key
Returns:
the resource bundle message or the key itself if no message is defined.
See Also:
msg
Returns the message from the default properties resource bundle (base
name "message") corresponding to the specified key and the request
locale. If no message for the key is found, returns the default message
if it is not null, otherwise returns the key itself.
This method is equivalent to msg(key, null, defaultMessage).
Parameters:
key
-
resource bundle message key
defaultMessage
-
default message to return if no message corresponding to the key is found
Returns:
the resource bundle message or default message
See Also:
msg
Returns the message from the specified properties resource bundle. The
resource bundle is located by iterating the site cartridges and looking
for a bundle with the specified name in the cartridge template/resources
directory. If it finds a bundle, it tries to return a message from the
bundle using standard Java ResourceBundle logic. If a message is found in
that cartridge's bundle, it is returned, otherwise, the next cartridge is
examined.
The method throws an exception if the key is null.
Parameters:
key
-
resource bundle message key
bundleName
-
base bundle name, if null, default bundle name, "message", is used
defaultMessage
-
default message to return if no message corresponding to the key is found and defaultMessage is not null
Returns:
the resource bundle message or default message
msgf
Returns the message from the specified properties resource bundle, with
the provided arguments substituted for the message argument placeholders
(specified using the Java MessageFormat approach).
If null is passed for the varargs argument, this method is equivalent to
msg(key, bundleName, defaultMessage).
Parameters:
key
-
resource bundle message key
bundleName
-
base bundle name, if null, default bundle name, "message", is used
defaultMessage
-
default message to return if no message corresponding to the key is found and defaultMessage is not null
args
-
optional list of arguments or a collection, which are included into the result string
Returns:
the resource bundle message or default message
See Also:
© Copyright 2000-2024, salesforce.com inc. All rights reserved. Various trademarks held by their respective owners.