Class I18nUtil


public class I18nUtil extends I18nConstants
Helper method for completed support of advanced internationalization in JCMS.
Since:
jcms-8.0.1
  • Constructor Details

    • I18nUtil

      public I18nUtil()
  • Method Details

    • getLocale

      public static Locale getLocale(String languageKey)
      Builds a new Locale from a language code, preserving any script indication that may be part of the language parameter.

      Script is only preserved when running on Java 1.7 (thus, you must run with Java 1.7 for advanced language support).

      Parameters:
      languageKey - an ISO-639 language code (eg fr), with an optional script indication (eg zh-Hant)
      Returns:
      a new Locale instance
      Throws:
      IllegalArgumentException - if languageKey is null
      Since:
      jcms-8.0.1
      See Also:
    • getLocale

      public static Locale getLocale(String languageKey, String country)
      Builds a new Locale from a language and country code preserving any script indication that may be part of the language parameter.

      Script is only preserved when running on Java 1.7 (thus, you must run with Java 1.7 for advanced language support).

      Parameters:
      languageKey - an ISO-639 language code (eg fr), with an optional script indication (eg zh-Hant)
      country - An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code. See the Locale class description about valid country values
      Returns:
      a new Locale instance
      Throws:
      IllegalArgumentException - if languageKey or country is null
      Since:
      jcms-8.0.1
      See Also:
    • getLanguageKey

      public static String getLanguageKey(Locale locale)
      Retrieve the language key to use as valid parameter of JCMS I18Ned API.

      Given ANY Locale, this method will find the most appropriate language in which JCMS currently configured, then return the corresponding language key.
      If no suitable language could be found for the specified Locale (or if specified Locale is null) it will default to the main site language.

      This method behavior depends on the current site configuration, as only language configured on the site will be returned.

      Parameters:
      locale - any Locale
      Returns:
      a string identifying a language in which JCMS is currently configured, thus suitable for use as parameter of JcmsUtil.glp(String, String, Object...) methods as well as all access to translated data values. never return null.
      Since:
      jcms-8.0.1
    • getJcmsTranslatedLanguageKey

      public static String getJcmsTranslatedLanguageKey(Locale locale)
      Retrieve the key of a language in which JCMS is translated, for the specified Locale.

      Given ANY Locale, this method will find the most appropriate language in which JCMS is translated, then return the corresponding language key used by JCMS.
      If no suitable language could be found for the specified Locale, null is returned.

      This method behavior does not depends on the current site configuration.

      Parameters:
      locale - any Locale
      Returns:
      a string identifying a language in which JCMS is translated, or null if no matching language could be found for the specified Locale
      Since:
      jcms-8.0.1
    • getValidLanguageKey

      public static String getValidLanguageKey(String languageKey)
      Retrieve the language key to use as valid parameter of JCMS I18Ned API.

      Given ANY language (and its optional script variation), this method will find the most appropriate language in which JCMS is currently configured, then return the corresponding language key.
      If no suitable language could be found for the specified language (or if specified language is null) it will default to the main site language.

      This method behavior depends on the current site configuration, as only language configured on the site will be returned.

      Parameters:
      languageKey - a string identifying a language and its optional script variation, eg ISO-639 ("en", "fr", "zh") or BCP 47 ("zh-Hant")
      Returns:
      a string identifying a language in which JCMS is currently configured, thus suitable for use as parameter of JcmsUtil.glp(String, String, Object...) methods as well as all access to translated data values. never return null.
      Since:
      jcms-8.0.1