Class TranslateBundleFunction

  • All Implemented Interfaces:
    TemplateFunction, java.util.function.Function<java.lang.String,​java.lang.String>

    public class TranslateBundleFunction
    extends java.lang.Object
    implements TemplateFunction
    Mustache.java translation function based on localized ResourceBundles. Usage code with a class: public class ... { TemplateFunction trans = new TranslateBundleFunction("com.project.locale", Locale.US); ... } Usage code with a Map: HashMap<String, Object> scopes = new HashMap<String, Object>(); scopes.put("trans", new TranslateBundleFunction("com.project.locale", Locale.US)); ... Usage in template: ... {{#trans}}TranslatedLabel1{{/trans}} ... ... {{#trans}}TranslatedLabel2 param1=newparam1 param2=newparma2{{/trans}}
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ResourceBundle res  
    • Constructor Summary

      Constructors 
      Constructor Description
      TranslateBundleFunction​(java.lang.String bundle, java.util.Locale locale)
      Constructor for a Mustache.java translation function.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String apply​(java.lang.String input)
      Return translation from the localized ResourceBundle.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Field Detail

      • res

        private java.util.ResourceBundle res
    • Constructor Detail

      • TranslateBundleFunction

        public TranslateBundleFunction​(java.lang.String bundle,
                                       java.util.Locale locale)
        Constructor for a Mustache.java translation function.
        Parameters:
        bundle - resource bundle name
        locale - translation locale
    • Method Detail

      • apply

        public java.lang.String apply​(java.lang.String input)
        Return translation from the localized ResourceBundle.
        Specified by:
        apply in interface java.util.function.Function<java.lang.String,​java.lang.String>