Enum I18nHelper

java.lang.Object
java.lang.Enum<I18nHelper>
com.github.jknack.handlebars.helper.I18nHelper
All Implemented Interfaces:
Helper<String>, Serializable, Comparable<I18nHelper>, java.lang.constant.Constable

public enum I18nHelper extends Enum<I18nHelper> implements Helper<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:
  • Enum Constant Details

    • 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:
    • 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 Details

    • values

      public static I18nHelper[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static I18nHelper valueOf(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:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • setCharset

      public void setCharset(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(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(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.