Class BundleFunctions


  • public class BundleFunctions
    extends java.lang.Object
    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}}
    • Constructor Summary

      Constructors 
      Constructor Description
      BundleFunctions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      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.
      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.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BundleFunctions

        public BundleFunctions()
    • 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 from replaceMe to the value replaced, the following output will be generated:
         hello
         Label.unknown
         Label.replaced
         
        Parameters:
        bundle - name of the resource bundle
        locale - 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 from replaceMe to the value replaced, the following output will be generated:
         hello
         
        Parameters:
        bundle - name of the resource bundle
        locale - 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 from replaceMe to the value replaced, the following output will be generated:
         hello
         Label.unknown
         world
         
        Parameters:
        bundle - name of the resource bundle
        locale - 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 from replaceMe to the value replaced, the following output will be generated:
         hello
         world
         
        Parameters:
        bundle - name of the resource bundle
        locale - translation locale
        Returns:
        Function that operates after template evaluation and returns nulls for unknown keys