Package com.vmware.vipclient.i18n.util
Class LocaleUtility
- java.lang.Object
-
- com.vmware.vipclient.i18n.util.LocaleUtility
-
public class LocaleUtility extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description LocaleUtility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.LocalefmtToMappedLocale(java.lang.String zhLocale)static java.util.LocalefmtToMappedLocale(java.util.Locale zhLocale)static java.util.LocalegetDefaultLocale()static java.util.List<java.util.Locale>getFallbackLocales()static java.util.LocalegetL2Locale()get the locale from ThreadLocalstatic java.util.LocalegetLocale()get the locale from ThreadLocalstatic java.util.LocalegetSourceLocale()static booleanisDefaultLocale(java.lang.String languageTag)static booleanisDefaultLocale(java.util.Locale locale)static booleanisLanguageTag(java.lang.String languageTag)validate that an argument is a well-formed BCP 47 tagstatic java.util.Set<java.util.Locale>langTagtoLocaleSet(java.util.Set<java.lang.String> languageTags)static java.lang.StringnormalizeToLanguageTag(java.lang.String localeStr)normalize a locale string(e.g.static java.util.LocalepickupLocaleFromList(java.util.Set<java.util.Locale> locales, java.util.Locale preferredLocale)Iterates over the set of locales to find a locale that best matches the preferredLocale.static voidsetDefaultLocale(java.util.Locale defaultLocale)static voidsetFallbackLocales(java.util.List<java.util.Locale> fallbackLocales)static voidsetL2Locale(java.util.Locale locale)Set the locale to ThreadLocalstatic voidsetLocale(java.util.Locale locale)Set the locale to ThreadLocalstatic voidsetSourceLocale(java.util.Locale sourceLocale)
-
-
-
Method Detail
-
setLocale
public static void setLocale(java.util.Locale locale)
Set the locale to ThreadLocal- Parameters:
locale-
-
getLocale
public static java.util.Locale getLocale()
get the locale from ThreadLocal
-
setL2Locale
public static void setL2Locale(java.util.Locale locale)
Set the locale to ThreadLocal- Parameters:
locale-
-
getL2Locale
public static java.util.Locale getL2Locale()
get the locale from ThreadLocal
-
isDefaultLocale
public static boolean isDefaultLocale(java.util.Locale locale)
-
isDefaultLocale
public static boolean isDefaultLocale(java.lang.String languageTag)
-
fmtToMappedLocale
public static java.util.Locale fmtToMappedLocale(java.lang.String zhLocale)
-
fmtToMappedLocale
public static java.util.Locale fmtToMappedLocale(java.util.Locale zhLocale)
-
pickupLocaleFromList
public static java.util.Locale pickupLocaleFromList(java.util.Set<java.util.Locale> locales, java.util.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 java.lang.String normalizeToLanguageTag(java.lang.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(java.lang.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 java.util.Locale getDefaultLocale()
-
setDefaultLocale
public static void setDefaultLocale(java.util.Locale defaultLocale)
-
getSourceLocale
public static java.util.Locale getSourceLocale()
-
setSourceLocale
public static void setSourceLocale(java.util.Locale sourceLocale)
-
getFallbackLocales
public static java.util.List<java.util.Locale> getFallbackLocales()
-
setFallbackLocales
public static void setFallbackLocales(java.util.List<java.util.Locale> fallbackLocales)
-
langTagtoLocaleSet
public static java.util.Set<java.util.Locale> langTagtoLocaleSet(java.util.Set<java.lang.String> languageTags)
-
-