Class I18nUtil
- 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetJcmsTranslatedLanguageKey(Locale locale) Retrieve the key of a language in which JCMS is translated, for the specified Locale.static StringgetLanguageKey(Locale locale) Retrieve the language key to use as valid parameter of JCMS I18Ned API.static LocaleBuilds a new Locale from a language code, preserving any script indication that may be part of the language parameter.static LocaleBuilds a new Locale from a language and country code preserving any script indication that may be part of the language parameter.static StringgetValidLanguageKey(String languageKey) Retrieve the language key to use as valid parameter of JCMS I18Ned API.
-
Constructor Details
-
I18nUtil
public I18nUtil()
-
-
Method Details
-
getLocale
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:
IllegalArgumentException- if languageKey is null- Since:
- jcms-8.0.1
- See Also:
-
getLocale
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:
IllegalArgumentException- if languageKey or country is null- Since:
- jcms-8.0.1
- See Also:
-
getLanguageKey
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
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
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
-