Class I18nUtil
- java.lang.Object
-
- com.jalios.jcms.i18n.I18nConstants
-
- com.jalios.jcms.i18n.I18nUtil
-
public class I18nUtil extends I18nConstants
Helper method for completed support of advanced internationalization in JCMS.- Since:
- jcms-8.0.1
-
-
Field Summary
-
Fields inherited from class com.jalios.jcms.i18n.I18nConstants
LANGUAGE_PROPERTIES_FILENAME_REGEX, PROPERTIES_ONLY_NO_FALLBACK_CONTROL
-
-
Constructor Summary
Constructors Constructor Description I18nUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getJcmsTranslatedLanguageKey(java.util.Locale locale)
Retrieve the key of a language in which JCMS is translated, for the specified Locale.static java.lang.String
getLanguageKey(java.util.Locale locale)
Retrieve the language key to use as valid parameter of JCMS I18Ned API.static java.util.Locale
getLocale(java.lang.String languageKey)
Builds a new Locale from a language code, preserving any script indication that may be part of the language parameter.static java.util.Locale
getLocale(java.lang.String languageKey, java.lang.String country)
Builds a new Locale from a language and country code preserving any script indication that may be part of the language parameter.static java.lang.String
getValidLanguageKey(java.lang.String languageKey)
Retrieve the language key to use as valid parameter of JCMS I18Ned API.
-
-
-
Method Detail
-
getLocale
public static java.util.Locale getLocale(java.lang.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 (egfr
), with an optional script indication (egzh-Hant
)- Returns:
- a new Locale instance
- Throws:
java.lang.IllegalArgumentException
- if languageKey is null- Since:
- jcms-8.0.1
- See Also:
getLanguageKey(Locale)
-
getLocale
public static java.util.Locale getLocale(java.lang.String languageKey, java.lang.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 (egfr
), with an optional script indication (egzh-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:
java.lang.IllegalArgumentException
- if languageKey or country is null- Since:
- jcms-8.0.1
- See Also:
getLanguageKey(Locale)
-
getLanguageKey
public static java.lang.String getLanguageKey(java.util.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 java.lang.String getJcmsTranslatedLanguageKey(java.util.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 java.lang.String getValidLanguageKey(java.lang.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
-
-