Package com.vmware.vipclient.i18n.util
Class LocaleUtility
java.lang.Object
com.vmware.vipclient.i18n.util.LocaleUtility
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalefmtToMappedLocale(String zhLocale) static LocalefmtToMappedLocale(Locale zhLocale) static Localestatic Localeget the locale from ThreadLocalstatic Localeget the locale from ThreadLocalstatic Localestatic booleanisDefaultLocale(String languageTag) static booleanisDefaultLocale(Locale locale) static booleanisLanguageTag(String languageTag) validate that an argument is a well-formed BCP 47 taglangTagtoLocaleSet(Set<String> languageTags) static StringnormalizeToLanguageTag(String localeStr) normalize a locale string(e.g.static LocalepickupLocaleFromList(Set<Locale> locales, Locale preferredLocale) Iterates over the set of locales to find a locale that best matches the preferredLocale.static voidsetDefaultLocale(Locale defaultLocale) static voidsetFallbackLocales(List<Locale> fallbackLocales) static voidsetL2Locale(Locale locale) Set the locale to ThreadLocalstatic voidSet the locale to ThreadLocalstatic voidsetSourceLocale(Locale sourceLocale)
-
Constructor Details
-
LocaleUtility
public LocaleUtility()
-
-
Method Details
-
setLocale
Set the locale to ThreadLocal- Parameters:
locale-
-
getLocale
get the locale from ThreadLocal -
setL2Locale
Set the locale to ThreadLocal- Parameters:
locale-
-
getL2Locale
get the locale from ThreadLocal -
isDefaultLocale
-
isDefaultLocale
-
fmtToMappedLocale
-
fmtToMappedLocale
-
pickupLocaleFromList
Iterates over the set of locales to find a locale that best matches the preferredLocale.
A "best match" is defined to be the locale that has the longest common language tag with the preferredLocale. For example, the supported locale 'de' will be returned for a non-supported preferredLocale 'de-DE'.To meet the custom usage of Chinese language, locale "zh" is not considered as a "match" for any non-supported Chinese locale (zh-*). That is, even if "zh" locale is supported,
nullwill be returned for Chinese locale 'zh-HK' that is not supported.- Parameters:
locales- the set of locales to find the best match from.preferredLocale- the locale being matched.- Returns:
- the best match, if any;
nullotherwise.
-
normalizeToLanguageTag
normalize a locale string(e.g. 'zh__#Hans', 'zh_CN_#Hans') to language tag(e.g. 'zh-Hans', 'zh-Hans-CN'). -
isLanguageTag
validate that an argument is a well-formed BCP 47 tag- Parameters:
languageTag-- Returns:
- true if the format is fine
-
getDefaultLocale
-
setDefaultLocale
-
getSourceLocale
-
setSourceLocale
-
getFallbackLocales
-
setFallbackLocales
-
langTagtoLocaleSet
-