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.Locale
fmtToMappedLocale(java.lang.String zhLocale)
static java.util.Locale
fmtToMappedLocale(java.util.Locale zhLocale)
static java.util.Locale
getDefaultLocale()
static java.util.List<java.util.Locale>
getFallbackLocales()
static java.util.Locale
getL2Locale()
get the locale from ThreadLocalstatic java.util.Locale
getLocale()
get the locale from ThreadLocalstatic java.util.Locale
getSourceLocale()
static boolean
isDefaultLocale(java.lang.String languageTag)
static boolean
isDefaultLocale(java.util.Locale locale)
static boolean
isLanguageTag(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.String
normalizeToLanguageTag(java.lang.String localeStr)
normalize a locale string(e.g.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.static void
setDefaultLocale(java.util.Locale defaultLocale)
static void
setFallbackLocales(java.util.List<java.util.Locale> fallbackLocales)
static void
setL2Locale(java.util.Locale locale)
Set the locale to ThreadLocalstatic void
setLocale(java.util.Locale locale)
Set the locale to ThreadLocalstatic void
setSourceLocale(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.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,
null
will 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;
null
otherwise.
-
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)
-
-