public class ResourceBundleHelper extends LocaleAwareValueHelper
First register the helper instance:
MustacheEngineBuilder.newBuilder().registerHelper("msg", new ResourceBundleHelper("messages")).build();
Than use the helper in the template:
{{msg "my.key"}}
The key need not be a string literal:
{{msg foo.key}}
You may also override the default baseName:
{{msg "my.key" baseName="messages"}}
And also use message parameters and Formatter
or
MessageFormat
:
hello.key=Hello %s!
{{msg "hello.key" "world" format="printf"}}
See also ResourceBundleHelper.Format
for more info about formats.
Since 1.7 a custom Locale
can be set via options hash with
OptionsHashKeys.LOCALE
key. See also
LocaleAwareValueHelper.getLocale(Options)
.
{{msg "key" locale="fr"}}
LocaleSupport
Modifier and Type | Class and Description |
---|---|
static class |
ResourceBundleHelper.Format |
VALUE_TAG_TYPES
HELPER_TAG_TYPES
configuration
Constructor and Description |
---|
ResourceBundleHelper(String defaultBaseName) |
ResourceBundleHelper(String defaultBaseName,
ResourceBundleHelper.Format defaultFormat) |
Modifier and Type | Method and Description |
---|---|
void |
execute(Options options)
Execute the helper.
|
protected Set<String> |
getSupportedHashKeys() |
getCurrentLocale, getCurrentLocale, getLocale, init
allowedTagTypes
getRequiredHashKeys, numberOfRequiredHashEntries, numberOfRequiredParameters, validate
append, convertAndAppend, convertValue, isSection, isUnescapeVariable, isVariable
checkNotInitialized, init
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConfigurationKeys, init
public ResourceBundleHelper(String defaultBaseName)
defaultBaseName
- public ResourceBundleHelper(String defaultBaseName, ResourceBundleHelper.Format defaultFormat)
defaultBaseName
- defaultFormat
- public void execute(Options options)
Helper
protected Set<String> getSupportedHashKeys()
getSupportedHashKeys
in class LocaleAwareValueHelper
*
to
allow any hash keysCopyright © 2017. All rights reserved.