Package com.vmware.vipclient.i18n.util
Class LocaleUtility
- java.lang.Object
-
- com.vmware.vipclient.i18n.util.LocaleUtility
-
public class LocaleUtility extends Object
-
-
Constructor Summary
Constructors Constructor Description LocaleUtility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LocalefmtToMappedLocale(String zhLocale)static LocalefmtToMappedLocale(Locale zhLocale)static LocalegetDefaultLocale()static List<Locale>getFallbackLocales()static LocalegetL2Locale()get the locale from ThreadLocalstatic LocalegetLocale()get the locale from ThreadLocalstatic LocalegetSourceLocale()static booleanisDefaultLocale(String languageTag)static booleanisDefaultLocale(Locale locale)static booleanisLanguageTag(String languageTag)validate that an argument is a well-formed BCP 47 tagstatic Set<Locale>langTagtoLocaleSet(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 voidsetLocale(Locale locale)Set the locale to ThreadLocalstatic voidsetSourceLocale(Locale sourceLocale)
-
-
-
Method Detail
-
setLocale
public static void setLocale(Locale locale)
Set the locale to ThreadLocal- Parameters:
locale-
-
getLocale
public static Locale getLocale()
get the locale from ThreadLocal
-
setL2Locale
public static void setL2Locale(Locale locale)
Set the locale to ThreadLocal- Parameters:
locale-
-
getL2Locale
public static Locale getL2Locale()
get the locale from ThreadLocal
-
isDefaultLocale
public static boolean isDefaultLocale(Locale locale)
-
isDefaultLocale
public static boolean isDefaultLocale(String languageTag)
-
pickupLocaleFromList
public static Locale pickupLocaleFromList(Set<Locale> locales, Locale preferredLocale)
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
public static String normalizeToLanguageTag(String localeStr)
normalize a locale string(e.g. 'zh__#Hans', 'zh_CN_#Hans') to language tag(e.g. 'zh-Hans', 'zh-Hans-CN').
-
isLanguageTag
public static boolean isLanguageTag(String languageTag)
validate that an argument is a well-formed BCP 47 tag- Parameters:
languageTag-- Returns:
- true if the format is fine
-
getDefaultLocale
public static Locale getDefaultLocale()
-
setDefaultLocale
public static void setDefaultLocale(Locale defaultLocale)
-
getSourceLocale
public static Locale getSourceLocale()
-
setSourceLocale
public static void setSourceLocale(Locale sourceLocale)
-
-