Class BundleFunctions
- java.lang.Object
-
- com.github.mustachejava.functions.BundleFunctions
-
public class BundleFunctions extends java.lang.ObjectFactory 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 Classes Modifier and Type Class Description private static classBundleFunctions.BundleFunc(package private) static classBundleFunctions.PostTranslateFunc(package private) static classBundleFunctions.PreTranslateFunc
-
Constructor Summary
Constructors Constructor Description BundleFunctions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.function.FunctionnewPostTranslate(java.lang.String bundle, java.util.Locale locale)Returns a Function that operates after template evaluation and returns unknown keys intact.static java.util.function.FunctionnewPostTranslateNullableLabel(java.lang.String bundle, java.util.Locale locale)Returns a Function that operates after template evaluation and returns nulls for unknown keys.static java.util.function.FunctionnewPreTranslate(java.lang.String bundle, java.util.Locale locale)Returns a Function that operates prior to template evaluation and returns unknown keys intact.static java.util.function.FunctionnewPreTranslateNullableLabel(java.lang.String bundle, java.util.Locale locale)Returns a Function that operates prior to template evaluation and returns nulls for unknown keys.
-
-
-
Method Detail
-
newPreTranslate
public static java.util.function.Function newPreTranslate(java.lang.String bundle, java.util.Locale locale)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
public static java.util.function.Function newPreTranslateNullableLabel(java.lang.String bundle, java.util.Locale locale)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
public static java.util.function.Function newPostTranslate(java.lang.String bundle, java.util.Locale locale)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
public static java.util.function.Function newPostTranslateNullableLabel(java.lang.String bundle, java.util.Locale locale)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
-
-