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_TYPESHELPER_TAG_TYPESconfiguration| 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, initallowedTagTypesgetRequiredHashKeys, numberOfRequiredHashEntries, numberOfRequiredParameters, validateappend, convertAndAppend, convertValue, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConfigurationKeys, initpublic ResourceBundleHelper(String defaultBaseName)
defaultBaseName - public ResourceBundleHelper(String defaultBaseName, ResourceBundleHelper.Format defaultFormat)
defaultBaseName - defaultFormat - public void execute(Options options)
Helperprotected Set<String> getSupportedHashKeys()
getSupportedHashKeys in class LocaleAwareValueHelper* to
allow any hash keysCopyright © 2017. All rights reserved.