public class BundleFunctions extends Object
public class ... {
Function trans = BundleFunctions.newPreTranslate("com.project.locale", Locale.US);
...
}
Example with a map:
Map <String, Object> scopes = new HashMap%lt;String, Object>();
scopes.put("trans", BundleFunctions.newPostTranslateNullableLabel("com.project.locale", Locale.US);
...
Usage in template:
{{#trans}}TranslatedLabel1{{/trans}}| Constructor and Description |
|---|
BundleFunctions() |
| Modifier and Type | Method and Description |
|---|---|
static Function |
newPostTranslate(String bundle,
Locale locale)
Returns a Function that operates after template evaluation and returns unknown keys intact.
|
static Function |
newPostTranslateNullableLabel(String bundle,
Locale locale)
Returns a Function that operates after template evaluation and returns nulls for unknown keys.
|
static Function |
newPreTranslate(String bundle,
Locale locale)
Returns a Function that operates prior to template evaluation and returns unknown keys intact.
|
static Function |
newPreTranslateNullableLabel(String bundle,
Locale locale)
Returns a Function that operates prior to template evaluation and returns nulls for unknown keys.
|
public static Function newPreTranslate(String bundle, Locale locale)
{{#trans}}Label1{{/trans}}
{{#trans}}Label.unknown{{/trans}}
{{#trans}}Label.{{replaceMe}}{{/trans}}
and the following properties in the provided bundle:
Label1=hello Label.replaced=worldand a mapping from
replaceMe to the value replaced, the following output
will be generated:
hello Label.unknown Label.replaced
bundle - name of the resource bundlelocale - translation localepublic static Function newPreTranslateNullableLabel(String bundle, Locale locale)
{{#trans}}Label1{{/trans}}
{{#trans}}Label.unknown{{/trans}}
{{#trans}}Label.{{replaceMe}}{{/trans}}
and the following properties in the provided bundle:
Label1=hello Label.replaced=worldand a mapping from
replaceMe to the value replaced, the following output
will be generated:
hello
bundle - name of the resource bundlelocale - translation localepublic static Function newPostTranslate(String bundle, Locale locale)
{{#trans}}Label1{{/trans}}
{{#trans}}Label.unknown{{/trans}}
{{#trans}}Label.{{replaceMe}}{{/trans}}
and the following properties in the provided bundle:
Label1=hello Label.replaced=worldand a mapping from
replaceMe to the value replaced, the following output
will be generated:
hello Label.unknown world
bundle - name of the resource bundlelocale - translation localepublic static Function newPostTranslateNullableLabel(String bundle, Locale locale)
{{#trans}}Label1{{/trans}}
{{#trans}}Label.unknown{{/trans}}
{{#trans}}Label.{{replaceMe}}{{/trans}}
and the following properties in the provided bundle:
Label1=hello Label.replaced=worldand a mapping from
replaceMe to the value replaced, the following output
will be generated:
hello world
bundle - name of the resource bundlelocale - translation localeCopyright © 2018. All rights reserved.