public abstract class LocaleUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Locale |
fromString(String localeAsString,
boolean countryRequired)
Converts a String to a Locale.
|
static String |
validateCountryCode(String countryCode)
Validates the specified country code.
|
static String |
validateCountryCode(String countryCode,
String defaultCountryCode)
Validates the specified country code.
|
static String |
validateLanguageCode(String languageCode)
Validates the specified language code.
|
static String |
validateLanguageCode(String languageCode,
String defaultLanguageCode)
Validates the specified language code.
|
public static String validateLanguageCode(String languageCode)
Locale.getAvailableLocales() as
two letter or iso3 letter code. If the language code is not valid or is null, the language code of the
system will be returned.languageCode - the language code to validate (can be null)public static String validateLanguageCode(String languageCode, String defaultLanguageCode)
Locale.getAvailableLocales() as
two letter or iso3 letter code. If the language code is not valid, the default language code will be validated.
If even the default language code is not valid, the language code of the system will be returned. So even if one
of the language codes is null, a valid language code will be returned.languageCode - the language code to validate (can be null)defaultLanguageCode - the default language code (can be null)public static String validateCountryCode(String countryCode)
Locale.getAvailableLocales() as
two letter or iso3 letter code. If the country code is not valid or is null, the country code of the
system will be returned.countryCode - the country code to validate (can be null)public static String validateCountryCode(String countryCode, String defaultCountryCode)
Locale.getAvailableLocales() as
two letter or iso3 letter code. If the country code is not valid, the default country code will be validated.
If even the default country code is not valid, the country code of the system will be returned. So even if one
of the country codes is null, a valid country code will be returned.countryCode - the country code to validate (can be null)defaultCountryCode - the default country code (can be null)public static Locale fromString(String localeAsString, boolean countryRequired)
Converts a String to a Locale.
This method takes the string format of a locale and creates the locale object from it.
LocaleUtils.toLocale(null) = new Locale(Locale.getDefault().getLanguage())
LocaleUtils.toLocale("") = new Locale(Locale.getDefault().getLanguage())
LocaleUtils.toLocale("en") = new Locale("en")
LocaleUtils.toLocale("en_GB") = new Locale("en", "GB")
LocaleUtils.toLocale("en_GB_xxx") = new Locale("en", "GB", "xxx")
This method validates the input not strictly:
The language code can be lowercase, uppercase or an ISO3 language code. The country code must be lowercase, uppercase or an ISO3 country code. The separator must be an underscore. The length doesn't matter.
localeAsString - the locale String to convert, null returns a locale with the deafult languagecountryRequired - if true the country will always be present in the resulting localeCopyright © 2017 bremersee.org. All rights reserved.