public final class LocaleId extends Object implements Comparable<Object>
| Modifier and Type | Field and Description |
|---|---|
static LocaleId |
ALL |
static LocaleId |
ARABIC
LocaleId constant for "ar".
|
static LocaleId |
AUTODETECT
Same as EMPTY, but reminds the user that some components
use EMPTY as a setting to enable locale auto detection.
|
static LocaleId |
CHINA_CHINESE
LocaleId constant for "zh-cn".
|
static LocaleId |
EMPTY
An empty locale.
|
static LocaleId |
ENGLISH
LocaleId constant for "en".
|
static LocaleId |
FRENCH
LocaleId constant for "fr".
|
static LocaleId |
GERMAN
LocaleId constant for "de".
|
static LocaleId |
HEBREW
LocaleId constant for "he".
|
static LocaleId |
ITALIAN
LocaleId constant for "it".
|
static LocaleId |
JAPANESE
LocaleId constant for "ja".
|
static LocaleId |
KOREAN
LocaleId constant for "ko".
|
static LocaleId |
PORTUGUESE
LocaleId constant for "pt".
|
static LocaleId |
RUSSIAN
LocaleId constant for "ru".
|
static LocaleId |
SPANISH
LocaleId constant for "es".
|
static LocaleId |
TAIWAN_CHINESE
LocaleId constant for "zh-tw".
|
static LocaleId |
US_ENGLISH
LocaleId constant for "en-US".
|
| Constructor and Description |
|---|
LocaleId(Locale loc)
Creates a new LocaleId for the given Java Locale.
|
LocaleId(String language)
Creates a new LocaleId for a given language code.
|
LocaleId(String locId,
boolean normalize)
Deprecated.
normalize is ignored. Use
fromString(String) to create a LocaleId from a code. |
LocaleId(String language,
String region)
Creates a new LocaleId for a given language code and region code.
|
LocaleId(String language,
String region,
String userPart)
Creates a new LocaleId for a given language code, region code, and a user part.
|
LocaleId(com.ibm.icu.util.ULocale uLoc)
Creates a new LocaleId for the given ICU Locale.
|
| Modifier and Type | Method and Description |
|---|---|
LocaleId |
clone()
Returns a clone of this LocaleId.
|
int |
compareTo(Object arg)
Compares this LocaleId with a given object.
|
static List<LocaleId> |
convertToLocaleIds(List<String> languageCodes)
Converts a list of language codes into
LocaleIds |
boolean |
equals(Object arg)
Indicates if a given object is equal to this localeId object.
|
boolean |
equalToString(String str)
Convenience method to compare a LocaleId to a String
|
static LocaleId |
fromBCP47(String langtag)
Creates a new LocaleId from a BCP-47 language tag.
|
static LocaleId |
fromBCP47(String langtag,
boolean strict)
Creates a new LocaleId from a BCP-47 language tag.
|
static LocaleId |
fromPOSIXLocale(String locId)
Creates a new LocaleId from a POSIX locale identifier.
|
static LocaleId |
fromString(String locId)
Creates a new LocaleId from a locale identifier (and validate it).
|
static LocaleId[] |
getAvailableLocales()
Gets an array of the LocaleId objects for all the Java locales installed on the system.
|
String |
getLanguage()
Gets the language code for this LocaleId.
|
String |
getOriginalLocId()
Deprecated.
this will go away. Locales are case insensitive.
|
String |
getRegion()
Gets the region code for this LocaleId.
|
String |
getScript()
Gets the script code for this LocaleId.
|
String |
getUserPart()
Gets the user part of this LocaleId.
|
String |
getVariant()
Gets the variant for this LocaleId.
|
static boolean |
hasCharactersAsNumeralSeparators(LocaleId localeId)
Checks whether the specified locale has characters as numeral separators.
|
int |
hashCode()
Returns a hash code value for this LocaleId.
|
static boolean |
isBidirectional(LocaleId locId)
Indicates if a given locale usually uses a bi-directional script.
|
static String |
replaceVariables(String input,
LocaleId srcLoc,
LocaleId trgLoc)
Replaces the locale/language variables in a given input string by their runtime values.
|
static String |
replaceVariables(String input,
String srcLoc,
String trgLoc)
Replaces the locale/language variables in a given input string by their runtime values.
|
boolean |
sameLanguageAs(LocaleId other)
Indicates if the language of a given LocaleId is the same as the one of this LocaleId.
|
boolean |
sameLanguageAs(String langCode)
Indicates if a given string has the same language as the one of this LocaleId.
|
boolean |
sameRegionAs(LocaleId other)
Indicates if the region of a given LocaleId is the same as the one of this LocaleId.
|
boolean |
sameRegionAs(String locId)
Indicates if a given string has the same region as the one of this LocaleId.
|
boolean |
sameUserPartAs(LocaleId other)
Indicates if the user part of a given LocaleId is the same as the one of this LocaleId.
|
boolean |
sameUserPartAs(String langCode)
Indicates if a given string has the same user part as the one of this LocaleId.
|
static String[] |
splitLanguageCode(String locId)
Deprecated.
don't use this. It only "understands" language + region,
but that is just a small part of what BCP 47 supports.
|
String |
toBCP47()
Gets the BCP-47 language tag for this LocaleId.
|
com.ibm.icu.util.ULocale |
toIcuLocale()
Gets the ICU ULocale object wrapped by this LocaleId.
|
Locale |
toJavaLocale()
Creates a new Java Locale object from this LocaleId.
|
String |
toPOSIXLocaleId()
Gets a POSIX locale identifier for this LocaleId.
|
String |
toString()
Gets the string representation of the LocaleId.
|
public static final LocaleId EMPTY
public static final LocaleId ALL
public static final LocaleId AUTODETECT
public static final LocaleId ARABIC
public static final LocaleId CHINA_CHINESE
public static final LocaleId TAIWAN_CHINESE
public static final LocaleId ENGLISH
public static final LocaleId US_ENGLISH
public static final LocaleId FRENCH
public static final LocaleId GERMAN
public static final LocaleId HEBREW
public static final LocaleId ITALIAN
public static final LocaleId JAPANESE
public static final LocaleId KOREAN
public static final LocaleId PORTUGUESE
public static final LocaleId RUSSIAN
public static final LocaleId SPANISH
@Deprecated public LocaleId(String locId, boolean normalize)
fromString(String) to create a LocaleId from a code.locId - a LocaleId stringnormalize - true if it needs to be normalized the string,
false to use as-it. When use as-it, the identifier is expected to be in lower-cases and use '-'
for separator.IllegalArgumentException - if the argument in invalid.public LocaleId(String language)
LocaleId(String, boolean) to create a new LocaleId from a locale identifier.language - the language code (e.g. "de" for German).IllegalArgumentException - if the argument in invalid.public LocaleId(String language, String region)
language - the language code (e.g. "es" for Spanish).region - the region code (e.g. "es" for Spain or "005" for South America.
This parameter is ignored if null or empty.IllegalArgumentException - if the argument in invalid.public LocaleId(String language, String region, String userPart)
language - the language code (e.g. "es" for Spanish).region - the region code (e.g. "es" for Spain or "005" for South America.userPart - the user part of locale.
The latter two parameters are ignored if null or empty.IllegalArgumentException - if the argument in invalid.public LocaleId(com.ibm.icu.util.ULocale uLoc)
uLoc - the ICU Locale object to use.IllegalArgumentException - if the argument in invalid.public LocaleId(Locale loc)
loc - the Java Locale object to use.IllegalArgumentException - if the argument in invalid.public static String replaceVariables(String input, LocaleId srcLoc, LocaleId trgLoc)
input - the string with the variables.srcLoc - the source locale code (can be null).trgLoc - the target locale code (can be null).public static String replaceVariables(String input, String srcLoc, String trgLoc)
input - the string with the variables.srcLoc - the source locale code (can be null).trgLoc - the target locale code (can be null).public String toString()
@Deprecated public String getOriginalLocId()
public LocaleId clone()
public int hashCode()
public boolean equalToString(String str)
Conflating this functionality in equals was error prone.
str - string to compare topublic boolean equals(Object arg)
equals in class Objectarg - the object to compare. This can be a LocaleId object
or a string. Any other object will always return false. If the parameter
is a string it is normalized before being compared.public int compareTo(Object arg)
compareTo in interface Comparable<Object>arg - the object to compare. If the parameter is a string it is normalized
before being compared.public static LocaleId fromString(String locId)
new LocaleId(locId, true);locId - the locale identifier to use (it will be normalized).IllegalArgumentException - if the argument is invalid.public static LocaleId fromPOSIXLocale(String locId)
locId - the POSIX locale identifier (e.g. "de-at.UTF-8@EURO")IllegalArgumentException - if the argument is invalid.public String toPOSIXLocaleId()
public static LocaleId fromBCP47(String langtag, boolean strict)
If strict is true the language tag must be well-formed
(see ICU4J ULocale) or an exception is thrown.
It rejects language tags that use '_' instead of '-', or have ill-formed "parts".
If strict is false then it accepts both '_' and '-', converts invalid
language id to "und", and discards ill-formed and following portions of the tag.
langtag - the language tag to use (e.g. "fr-CA")strict - the language tag parsing is stricterIllegalArgumentException - if the argument in invalid.public static LocaleId fromBCP47(String langtag)
langtag - the language tag to use (e.g. "fr-CA")IllegalArgumentException - if the argument in invalid.fromBCP47(String langtag, boolean strict)public String toBCP47()
public Locale toJavaLocale()
public com.ibm.icu.util.ULocale toIcuLocale()
public String getLanguage()
public String getRegion()
public String getScript()
public String getVariant()
public String getUserPart()
public boolean sameLanguageAs(LocaleId other)
other - the LocaleId object to compare.public boolean sameLanguageAs(String langCode)
langCode - the string to compare.public boolean sameRegionAs(LocaleId other)
other - the LocaleId object to compare.public boolean sameRegionAs(String locId)
locId - the string to compare.public boolean sameUserPartAs(LocaleId other)
other - the LocaleId object to compare.public boolean sameUserPartAs(String langCode)
langCode - the string to compare.public static LocaleId[] getAvailableLocales()
@Deprecated public static String[] splitLanguageCode(String locId)
LocaleId object is not desirable.
This method supports only simple ISO codes (not complex BCP-47 tags).locId - the locale code to process.public static boolean isBidirectional(LocaleId locId)
Note that this is not perfect as some languages use several scripts.
locId - the locale to check.public static boolean hasCharactersAsNumeralSeparators(LocaleId localeId)
localeId - The locale to check againsttrue - if the specified locale has characters as numeral separators
false - otherwiseCopyright © 2021. All rights reserved.