Enum I18nHelper

  • All Implemented Interfaces:
    Helper<java.lang.String>, java.io.Serializable, java.lang.Comparable<I18nHelper>

    public enum I18nHelper
    extends java.lang.Enum<I18nHelper>
    implements Helper<java.lang.String>
    Implementation of i18n helper for Java and JavaScript.

    The Java implementation use ResourceBundle.

    The JavaScript version use the I18n library. ResourceBundle are converted to JavaScript code.

    Since:
    0.9.0
    See Also:
    ResourceBundle
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      i18n
      A helper built on top of ResourceBundle.
      i18nJs
      Translate a ResourceBundle into JavaScript code.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void setCharset​(java.nio.charset.Charset charset)
      Set the charset to use.
      void setDefaultBundle​(java.lang.String bundle)
      Set the default bundle's name.
      void setDefaultLocale​(java.util.Locale locale)
      Set the default locale.
      void setSource​(I18nSource source)
      Set the message source.
      static I18nHelper valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static I18nHelper[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.github.jknack.handlebars.Helper

        apply
    • Enum Constant Detail

      • i18n

        public static final I18nHelper i18n

        A helper built on top of ResourceBundle. A ResourceBundle is the most well known mechanism for internationalization (i18n).

        messages.properties:

          hello=Hola
         

        Basic Usage:

          {{i18n "hello"}}
         

        Will result in: Hola

        Using a locale:

          {{i18n "hello" locale="es_AR"}}
         

        Using a different bundle:

          {{i18n "hello" bundle="myMessages"}}
         

        Using a message format:

          hello=Hola {0}!
         
          {{i18n "hello" "Handlebars.java"}}
         
        Since:
        0.9.0
        See Also:
        ResourceBundle
      • i18nJs

        public static final I18nHelper i18nJs

        Translate a ResourceBundle into JavaScript code. The generated code assume you added the I18n

        It converts message patterns like: Hi {0} into Hi {{arg0}}. This make possible to the I18n JS library to interpolate variables.

        Note: make sure you include I18n in your application. Otherwise, the generated code will fail.

        Usage:

          {{i18nJs locale?}}
         
        If locale argument is present it will translate that locale to JavaScript. Otherwise, the default locale.
    • Method Detail

      • values

        public static I18nHelper[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (I18nHelper c : I18nHelper.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static I18nHelper valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • setCharset

        public void setCharset​(java.nio.charset.Charset charset)
        Set the charset to use. NotThreadSafe Make sure to call this method ONCE at start time.
        Parameters:
        charset - Charset. Required.
      • setSource

        public void setSource​(I18nSource source)
        Set the message source. NotThreadSafe Make sure to call this method ONCE at start time.
        Parameters:
        source - The message source. Required.
      • setDefaultBundle

        public void setDefaultBundle​(java.lang.String bundle)
        Set the default bundle's name. Default is: messages and this method let you override the default bundle's name to something else. NotThreadSafe Make sure to call this method ONCE at start time.
        Parameters:
        bundle - The default's bundle name. Required.
      • setDefaultLocale

        public void setDefaultLocale​(java.util.Locale locale)
        Set the default locale. Default is system dependent and this method let you override the default bundle's name to something else. NotThreadSafe Make sure to call this method ONCE at start time.
        Parameters:
        locale - The default locale name. Required.