Class BundleFunctions
java.lang.Object
com.github.mustachejava.functions.BundleFunctions
Factory for Mustache.java translation functions based on localized Resource bundles.
Example with a class:
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}}-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class(package private) static class(package private) static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FunctionnewPostTranslate(String bundle, Locale locale) Returns a Function that operates after template evaluation and returns unknown keys intact.static FunctionnewPostTranslateNullableLabel(String bundle, Locale locale) Returns a Function that operates after template evaluation and returns nulls for unknown keys.static FunctionnewPreTranslate(String bundle, Locale locale) Returns a Function that operates prior to template evaluation and returns unknown keys intact.static FunctionnewPreTranslateNullableLabel(String bundle, Locale locale) Returns a Function that operates prior to template evaluation and returns nulls for unknown keys.
-
Constructor Details
-
BundleFunctions
public BundleFunctions()
-
-
Method Details
-
newPreTranslate
Returns a Function that operates prior to template evaluation and returns unknown keys intact. Given the following HTML:{{#trans}}Label1{{/trans}} {{#trans}}Label.unknown{{/trans}} {{#trans}}Label.{{replaceMe}}{{/trans}}and the following properties in the provided bundle:Label1=hello Label.replaced=world
and a mapping fromreplaceMeto the valuereplaced, the following output will be generated:hello Label.unknown Label.replaced
- Parameters:
bundle- name of the resource bundlelocale- translation locale- Returns:
- Function that operates prior to template evaluation and returns unknown keys intact
-
newPreTranslateNullableLabel
Returns a Function that operates prior to template evaluation and returns nulls for unknown keys. Given the following HTML:{{#trans}}Label1{{/trans}} {{#trans}}Label.unknown{{/trans}} {{#trans}}Label.{{replaceMe}}{{/trans}}and the following properties in the provided bundle:Label1=hello Label.replaced=world
and a mapping fromreplaceMeto the valuereplaced, the following output will be generated:hello
- Parameters:
bundle- name of the resource bundlelocale- translation locale- Returns:
- Function that operates prior to template evaluation and returns nulls for unknown keys
-
newPostTranslate
Returns a Function that operates after template evaluation and returns unknown keys intact. Given the following HTML:{{#trans}}Label1{{/trans}} {{#trans}}Label.unknown{{/trans}} {{#trans}}Label.{{replaceMe}}{{/trans}}and the following properties in the provided bundle:Label1=hello Label.replaced=world
and a mapping fromreplaceMeto the valuereplaced, the following output will be generated:hello Label.unknown world
- Parameters:
bundle- name of the resource bundlelocale- translation locale- Returns:
- Function that operates after template evaluation and returns unknown keys intact
-
newPostTranslateNullableLabel
Returns a Function that operates after template evaluation and returns nulls for unknown keys. Given the following HTML:{{#trans}}Label1{{/trans}} {{#trans}}Label.unknown{{/trans}} {{#trans}}Label.{{replaceMe}}{{/trans}}and the following properties in the provided bundle:Label1=hello Label.replaced=world
and a mapping fromreplaceMeto the valuereplaced, the following output will be generated:hello world
- Parameters:
bundle- name of the resource bundlelocale- translation locale- Returns:
- Function that operates after template evaluation and returns nulls for unknown keys
-