|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.icu.util.ULocale
public final class ULocale
[icu enhancement] ICU's replacement for java.util.Locale
. Methods, fields, and other functionality specific to ICU are labeled '[icu]'.
Locale
that provides additional
support for ICU protocol. In ICU 3.0 this class is enhanced to support
RFC 3066 language identifiers.
Many classes and services in ICU follow a factory idiom, in which a factory method or object responds to a client request with an object. The request includes a locale (the requested locale), and the returned object is constructed using data for that locale. The system may lack data for the requested locale, in which case the locale fallback mechanism will be invoked until a populated locale is found (the valid locale). Furthermore, even when a populated locale is found (the valid locale), further fallback may be required to reach a locale containing the specific data required by the service (the actual locale).
ULocale performs 'normalization' and 'canonicalization' of locale ids. Normalization 'cleans up' ICU locale ids as follows:
canonicalize
can be called to convert the id
to canonical form, or the canonicalInstance
factory method
can be called.
This class provides selectors VALID_LOCALE
and ACTUAL_LOCALE
intended for use in methods named
getLocale(). These methods exist in several ICU classes,
including Calendar
, Currency
, UFormat
,
BreakIterator
,
Collator
,
DateFormatSymbols
, and DecimalFormatSymbols
and their subclasses, if
any. Once an object of one of these classes has been created,
getLocale() may be called on it to determine the valid and
actual locale arrived at during the object's construction.
Note: The actual locale is returned correctly, but the valid locale is not, in most cases.
Locale
,
Serialized FormNested Class Summary | |
---|---|
static class |
ULocale.Builder
Builder is used to build instances of ULocale
from values configured by the setters. |
static class |
ULocale.Category
Enum for locale categories. |
static class |
ULocale.Type
Opaque selector enum for getLocale(). |
Field Summary | |
---|---|
static ULocale.Type |
ACTUAL_LOCALE
[icu] Selector for getLocale() indicating the locale of the resource containing the data. |
static ULocale |
CANADA
Useful constant for country/region. |
static ULocale |
CANADA_FRENCH
Useful constant for country/region. |
static ULocale |
CHINA
Useful constant for country/region. |
static ULocale |
CHINESE
Useful constant for language. |
static ULocale |
ENGLISH
Useful constant for language. |
static ULocale |
FRANCE
Useful constant for country/region. |
static ULocale |
FRENCH
Useful constant for language. |
static ULocale |
GERMAN
Useful constant for language. |
static ULocale |
GERMANY
Useful constant for country/region. |
static ULocale |
ITALIAN
Useful constant for language. |
static ULocale |
ITALY
Useful constant for country/region. |
static ULocale |
JAPAN
Useful constant for country/region. |
static ULocale |
JAPANESE
Useful constant for language. |
static ULocale |
KOREA
Useful constant for country/region. |
static ULocale |
KOREAN
Useful constant for language. |
static ULocale |
PRC
Useful constant for country/region. |
static char |
PRIVATE_USE_EXTENSION
[icu] The key for the private use locale extension ('x'). |
static ULocale |
ROOT
The root ULocale. |
static ULocale |
SIMPLIFIED_CHINESE
Useful constant for language. |
static ULocale |
TAIWAN
Useful constant for country/region. |
static ULocale |
TRADITIONAL_CHINESE
Useful constant for language. |
static ULocale |
UK
Useful constant for country/region. |
static char |
UNICODE_LOCALE_EXTENSION
[icu] The key for Unicode locale extension ('u'). |
static ULocale |
US
Useful constant for country/region. |
static ULocale.Type |
VALID_LOCALE
[icu] Selector for getLocale() indicating the most specific locale for which any data exists. |
Constructor Summary | |
---|---|
ULocale(String localeID)
[icu] Constructs a ULocale from a RFC 3066 locale ID. |
|
ULocale(String a,
String b)
Convenience overload of ULocale(String, String, String) for compatibility with java.util.Locale. |
|
ULocale(String a,
String b,
String c)
Constructs a ULocale from a localeID constructed from the three 'fields' a, b, and c. |
Method Summary | |
---|---|
static ULocale |
acceptLanguage(String acceptLanguageList,
boolean[] fallback)
[icu] Based on a HTTP formatted list of acceptable locales, determine an available locale for the user. |
static ULocale |
acceptLanguage(String acceptLanguageList,
ULocale[] availableLocales,
boolean[] fallback)
[icu] Based on a HTTP formatted list of acceptable locales, determine an available locale for the user. |
static ULocale |
acceptLanguage(ULocale[] acceptLanguageList,
boolean[] fallback)
[icu] Based on an ordered array of acceptable locales, determine an available locale for the user. |
static ULocale |
acceptLanguage(ULocale[] acceptLanguageList,
ULocale[] availableLocales,
boolean[] fallback)
[icu] Based on a list of acceptable locales, determine an available locale for the user. |
static ULocale |
addLikelySubtags(ULocale loc)
[icu] Adds the likely subtags for a provided locale ID, per the algorithm described in the following CLDR technical report: http://www.unicode.org/reports/tr35/#Likely_Subtags If the provided ULocale instance is already in the maximal form, or there is no data available available for maximization, it will be returned. |
static String |
canonicalize(String localeID)
[icu] Returns the canonical name for the specified locale ID. |
Object |
clone()
This is for compatibility with Locale-- in actuality, since ULocale is immutable, there is no reason to clone it, so this API returns 'this'. |
static ULocale |
createCanonical(String nonCanonicalID)
[icu] Creates a ULocale from the id by first canonicalizing the id. |
boolean |
equals(Object obj)
Returns true if the other object is another ULocale with the same full name, or is a String localeID that matches the full name. |
static ULocale |
forLanguageTag(String languageTag)
[icu] Returns a locale for the specified IETF BCP 47 language tag string. |
static ULocale |
forLocale(Locale loc)
[icu] Returns a ULocale object for a Locale . |
static ULocale[] |
getAvailableLocales()
[icu] Note: Unlike the Locale API, this returns an array of |
String |
getBaseName()
[icu] Returns the (normalized) base name for this locale. |
static String |
getBaseName(String localeID)
[icu] Returns the (normalized) base name for the specified locale. |
String |
getCharacterOrientation()
[icu] Returns this locale's layout orientation for characters. |
String |
getCountry()
Returns the country/region code for this locale, which will either be the empty string or an uppercase ISO 3166 2-letter code. |
static String |
getCountry(String localeID)
Returns the country/region code for this locale, which will either be the empty string or an uppercase ISO 3166 2-letter code. |
static ULocale |
getDefault()
Returns the current default ULocale. |
static ULocale |
getDefault(ULocale.Category category)
Returns the current default ULocale for the specified category. |
String |
getDisplayCountry()
Returns this locale's country localized for display in the default DISPLAY locale. |
static String |
getDisplayCountry(String localeID,
String displayLocaleID)
Returns a locale's country localized for display in the provided locale. |
static String |
getDisplayCountry(String localeID,
ULocale displayLocale)
Returns a locale's country localized for display in the provided locale. |
String |
getDisplayCountry(ULocale displayLocale)
Returns this locale's country localized for display in the provided locale. |
static String |
getDisplayKeyword(String keyword)
[icu] Returns a keyword localized for display in the default DISPLAY locale. |
static String |
getDisplayKeyword(String keyword,
String displayLocaleID)
[icu] Returns a keyword localized for display in the specified locale. |
static String |
getDisplayKeyword(String keyword,
ULocale displayLocale)
[icu] Returns a keyword localized for display in the specified locale. |
String |
getDisplayKeywordValue(String keyword)
[icu] Returns a keyword value localized for display in the default DISPLAY locale. |
static String |
getDisplayKeywordValue(String localeID,
String keyword,
String displayLocaleID)
[icu] Returns a keyword value localized for display in the specified locale. |
static String |
getDisplayKeywordValue(String localeID,
String keyword,
ULocale displayLocale)
[icu] Returns a keyword value localized for display in the specified locale. |
String |
getDisplayKeywordValue(String keyword,
ULocale displayLocale)
[icu] Returns a keyword value localized for display in the specified locale. |
String |
getDisplayLanguage()
Returns this locale's language localized for display in the default DISPLAY locale. |
static String |
getDisplayLanguage(String localeID,
String displayLocaleID)
Returns a locale's language localized for display in the provided locale. |
static String |
getDisplayLanguage(String localeID,
ULocale displayLocale)
Returns a locale's language localized for display in the provided locale. |
String |
getDisplayLanguage(ULocale displayLocale)
[icu] Returns this locale's language localized for display in the provided locale. |
String |
getDisplayLanguageWithDialect()
[icu] Returns this locale's language localized for display in the default DISPLAY locale. |
static String |
getDisplayLanguageWithDialect(String localeID,
String displayLocaleID)
[icu] Returns a locale's language localized for display in the provided locale. |
static String |
getDisplayLanguageWithDialect(String localeID,
ULocale displayLocale)
[icu] Returns a locale's language localized for display in the provided locale. |
String |
getDisplayLanguageWithDialect(ULocale displayLocale)
[icu] Returns this locale's language localized for display in the provided locale. |
String |
getDisplayName()
Returns this locale name localized for display in the default DISPLAY locale. |
static String |
getDisplayName(String localeID,
String displayLocaleID)
Returns the locale ID localized for display in the provided locale. |
static String |
getDisplayName(String localeID,
ULocale displayLocale)
Returns the locale ID localized for display in the provided locale. |
String |
getDisplayName(ULocale displayLocale)
Returns this locale name localized for display in the provided locale. |
String |
getDisplayNameWithDialect()
[icu] Returns this locale name localized for display in the default DISPLAY locale. |
static String |
getDisplayNameWithDialect(String localeID,
String displayLocaleID)
[icu] Returns the locale ID localized for display in the provided locale. |
static String |
getDisplayNameWithDialect(String localeID,
ULocale displayLocale)
[icu] Returns the locale ID localized for display in the provided locale. |
String |
getDisplayNameWithDialect(ULocale displayLocale)
[icu] Returns this locale name localized for display in the provided locale. |
String |
getDisplayScript()
[icu] Returns this locale's script localized for display in the default DISPLAY locale. |
static String |
getDisplayScript(String localeID,
String displayLocaleID)
[icu] Returns a locale's script localized for display in the provided locale. |
static String |
getDisplayScript(String localeID,
ULocale displayLocale)
[icu] Returns a locale's script localized for display in the provided locale. |
String |
getDisplayScript(ULocale displayLocale)
[icu] Returns this locale's script localized for display in the provided locale. |
String |
getDisplayVariant()
Returns this locale's variant localized for display in the default DISPLAY locale. |
static String |
getDisplayVariant(String localeID,
String displayLocaleID)
Returns a locale's variant localized for display in the provided locale. |
static String |
getDisplayVariant(String localeID,
ULocale displayLocale)
Returns a locale's variant localized for display in the provided locale. |
String |
getDisplayVariant(ULocale displayLocale)
Returns this locale's variant localized for display in the provided locale. |
String |
getExtension(char key)
[icu] Returns the extension (or private use) value associated with the specified key, or null if there is no extension associated with the key. |
Set<Character> |
getExtensionKeys()
[icu] Returns the set of extension keys associated with this locale, or the empty set if it has no extensions. |
ULocale |
getFallback()
[icu] Returns the fallback locale for this locale. |
static String |
getFallback(String localeID)
[icu] Returns the fallback locale for the specified locale, which might be the empty string. |
String |
getISO3Country()
Returns a three-letter abbreviation for this locale's country/region. |
static String |
getISO3Country(String localeID)
Returns a three-letter abbreviation for this locale's country/region. |
String |
getISO3Language()
Returns a three-letter abbreviation for this locale's language. |
static String |
getISO3Language(String localeID)
Returns a three-letter abbreviation for this locale's language. |
static String[] |
getISOCountries()
Returns a list of all 2-letter country codes defined in ISO 3166. |
static String[] |
getISOLanguages()
Returns a list of all 2-letter language codes defined in ISO 639. |
Iterator<String> |
getKeywords()
[icu] Returns an iterator over keywords for this locale. |
static Iterator<String> |
getKeywords(String localeID)
[icu] Returns an iterator over keywords for the specified locale. |
String |
getKeywordValue(String keywordName)
[icu] Returns the value for a keyword in this locale. |
static String |
getKeywordValue(String localeID,
String keywordName)
[icu] Returns the value for a keyword in the specified locale. |
String |
getLanguage()
Returns the language code for this locale, which will either be the empty string or a lowercase ISO 639 code. |
static String |
getLanguage(String localeID)
Returns the language code for the locale ID, which will either be the empty string or a lowercase ISO 639 code. |
String |
getLineOrientation()
[icu] Returns this locale's layout orientation for lines. |
String |
getName()
[icu] Returns the (normalized) full name for this locale. |
static String |
getName(String localeID)
[icu] Returns the (normalized) full name for the specified locale. |
String |
getScript()
[icu] Returns the script code for this locale, which might be the empty string. |
static String |
getScript(String localeID)
[icu] Returns the script code for the specified locale, which might be the empty string. |
Set<String> |
getUnicodeLocaleAttributes()
[icu] Returns the set of unicode locale attributes associated with this locale, or the empty set if it has no attributes. |
Set<String> |
getUnicodeLocaleKeys()
[icu] Returns the set of Unicode locale keys defined by this locale, or the empty set if this locale has none. |
String |
getUnicodeLocaleType(String key)
[icu] Returns the Unicode locale type associated with the specified Unicode locale key for this locale. |
String |
getVariant()
Returns the variant code for this locale, which might be the empty string. |
static String |
getVariant(String localeID)
Returns the variant code for the specified locale, which might be the empty string. |
int |
hashCode()
Returns the hashCode. |
static ULocale |
minimizeSubtags(ULocale loc)
[icu] Minimizes the subtags for a provided locale ID, per the algorithm described in the following CLDR technical report: http://www.unicode.org/reports/tr35/#Likely_Subtags If the provided ULocale instance is already in the minimal form, or there is no data available for minimization, it will be returned. |
static void |
setDefault(ULocale.Category category,
ULocale newLocale)
Sets the default ULocale for the specified Category . |
static void |
setDefault(ULocale newLocale)
[icu] Sets the default ULocale. |
ULocale |
setKeywordValue(String keyword,
String value)
Given a keyword and a value, return a new locale with an updated keyword and value. |
static String |
setKeywordValue(String localeID,
String keyword,
String value)
Given a locale id, a keyword, and a value, return a new locale id with an updated keyword and value. |
String |
toLanguageTag()
[icu] Returns a well-formed IETF BCP 47 language tag representing this locale. |
Locale |
toLocale()
[icu] Converts this ULocale object to a Locale . |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ULocale ENGLISH
public static final ULocale FRENCH
public static final ULocale GERMAN
public static final ULocale ITALIAN
public static final ULocale JAPANESE
public static final ULocale KOREAN
public static final ULocale CHINESE
public static final ULocale SIMPLIFIED_CHINESE
public static final ULocale TRADITIONAL_CHINESE
public static final ULocale FRANCE
public static final ULocale GERMANY
public static final ULocale ITALY
public static final ULocale JAPAN
public static final ULocale KOREA
public static final ULocale CHINA
public static final ULocale PRC
public static final ULocale TAIWAN
public static final ULocale UK
public static final ULocale US
public static final ULocale CANADA
public static final ULocale CANADA_FRENCH
public static final ULocale ROOT
public static ULocale.Type ACTUAL_LOCALE
public static ULocale.Type VALID_LOCALE
Note: The valid locale will be returned correctly in ICU 3.0 or later. In ICU 2.8, it is not returned correctly.
public static final char PRIVATE_USE_EXTENSION
getExtension(char)
,
ULocale.Builder.setExtension(char, String)
,
Constant Field Valuespublic static final char UNICODE_LOCALE_EXTENSION
getExtension(char)
,
ULocale.Builder.setExtension(char, String)
,
Constant Field ValuesConstructor Detail |
---|
public ULocale(String localeID)
This constructor does not canonicalize the localeID. So, for
example, "zh__pinyin" remains unchanged instead of converting
to "zh@collation=pinyin". By default ICU only recognizes the
latter as specifying pinyin collation. Use createCanonical(java.lang.String)
or canonicalize(java.lang.String)
if you need to canonicalize the localeID.
localeID
- string representation of the locale, e.g:
"en_US", "sy_Cyrl_YU", "zh__pinyin", "es_ES@currency=EUR;collation=traditional"public ULocale(String a, String b)
ULocale(String, String, String)
public ULocale(String a, String b, String c)
ULocale(String
localeID)
.
Java locale strings consisting of language, country, and variant will be handled by this form, since the country code (being shorter than four letters long) will not be interpreted as a script code. If a script code is present, the final argument ('c') will be interpreted as the country code. It is recommended that this constructor only be used to ease porting, and that clients instead use the single-argument constructor when constructing a ULocale from a localeID.
a
- first component of the locale idb
- second component of the locale idc
- third component of the locale idULocale(String)
Method Detail |
---|
public static ULocale forLocale(Locale loc)
Locale
.
The ULocale is canonicalized.
loc
- a JDK localepublic static ULocale createCanonical(String nonCanonicalID)
nonCanonicalID
- the locale id to canonicalize
public Locale toLocale()
Locale
.
public static ULocale getDefault()
public static void setDefault(ULocale newLocale)
By setting the default ULocale with this method, all of the default categoy locales are also set to the specified default ULocale.
newLocale
- the new default locale
SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow the operation.
NullPointerException
- if newLocale
is nullSecurityManager.checkPermission(java.security.Permission)
,
PropertyPermission
,
setDefault(Category, ULocale)
public static ULocale getDefault(ULocale.Category category)
category
- the category
public static void setDefault(ULocale.Category category, ULocale newLocale)
ULocale
for the specified Category
.
This also sets the default Locale
for the specified Category
of the JVM. If the caller does not have write permission to the
user.language property, a security exception will be thrown,
and the default ULocale for the specified Category will remain unchanged.
category
- the specified category to set the default localenewLocale
- the new default localeSecurityManager.checkPermission(java.security.Permission)
,
PropertyPermission
public Object clone()
clone
in class Object
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
public static ULocale[] getAvailableLocales()
[icu] Note: Unlike the Locale API, this returns an array of ULocale
,
not Locale
. Returns a list of all installed locales.
public static String[] getISOCountries()
public static String[] getISOLanguages()
public String getLanguage()
getDisplayLanguage()
,
getDisplayLanguage(ULocale)
public static String getLanguage(String localeID)
getDisplayLanguage()
,
getDisplayLanguage(ULocale)
public String getScript()
getDisplayScript()
,
getDisplayScript(ULocale)
public static String getScript(String localeID)
getDisplayScript()
,
getDisplayScript(ULocale)
public String getCountry()
getDisplayCountry()
,
getDisplayCountry(ULocale)
public static String getCountry(String localeID)
localeID
- The locale identification string.getDisplayCountry()
,
getDisplayCountry(ULocale)
public String getVariant()
getDisplayVariant()
,
getDisplayVariant(ULocale)
public static String getVariant(String localeID)
getDisplayVariant()
,
getDisplayVariant(ULocale)
public static String getFallback(String localeID)
public ULocale getFallback()
public String getBaseName()
public static String getBaseName(String localeID)
localeID
- the locale ID as a string
public String getName()
public static String getName(String localeID)
localeID
- the localeID as a string
public String toString()
toString
in class Object
public Iterator<String> getKeywords()
public static Iterator<String> getKeywords(String localeID)
public String getKeywordValue(String keywordName)
keywordName
- name of the keyword whose value is desired. Case insensitive.
public static String getKeywordValue(String localeID, String keywordName)
keywordName
- name of the keyword whose value is desired. Case insensitive.
public static String canonicalize(String localeID)
localeID
- the locale id
public ULocale setKeywordValue(String keyword, String value)
keyword
- the keyword to add/remove, or null to remove all keywords.value
- the value to add/set, or null to remove this particular keyword.
public static String setKeywordValue(String localeID, String keyword, String value)
localeID
- the locale id to modifykeyword
- the keyword to add/remove, or null to remove all keywords.value
- the value to add/set, or null to remove this particular keyword.
public String getISO3Language()
ftp://dkuug.dk/i18n/iso-639-2.txt
MissingResourceException
- Throws MissingResourceException if the
three-letter language abbreviation is not available for this locale.public static String getISO3Language(String localeID)
ftp://dkuug.dk/i18n/iso-639-2.txt
MissingResourceException
- Throws MissingResourceException if the
three-letter language abbreviation is not available for this locale.public String getISO3Country()
MissingResourceException
- Throws MissingResourceException if the
three-letter country abbreviation is not available for this locale.public static String getISO3Country(String localeID)
MissingResourceException
- Throws MissingResourceException if the
three-letter country abbreviation is not available for this locale.public String getDisplayLanguage()
DISPLAY
locale.
ULocale.Category.DISPLAY
public String getDisplayLanguage(ULocale displayLocale)
displayLocale
- the locale in which to display the name.
public static String getDisplayLanguage(String localeID, String displayLocaleID)
localeID
- the id of the locale whose language will be displayeddisplayLocaleID
- the id of the locale in which to display the name.
public static String getDisplayLanguage(String localeID, ULocale displayLocale)
localeID
- the id of the locale whose language will be displayed.displayLocale
- the locale in which to display the name.
public String getDisplayLanguageWithDialect()
DISPLAY
locale.
If a dialect name is present in the data, then it is returned.
ULocale.Category.DISPLAY
public String getDisplayLanguageWithDialect(ULocale displayLocale)
displayLocale
- the locale in which to display the name.
public static String getDisplayLanguageWithDialect(String localeID, String displayLocaleID)
localeID
- the id of the locale whose language will be displayeddisplayLocaleID
- the id of the locale in which to display the name.
public static String getDisplayLanguageWithDialect(String localeID, ULocale displayLocale)
localeID
- the id of the locale whose language will be displayed.displayLocale
- the locale in which to display the name.
public String getDisplayScript()
DISPLAY
locale.
ULocale.Category.DISPLAY
public String getDisplayScript(ULocale displayLocale)
displayLocale
- the locale in which to display the name.
public static String getDisplayScript(String localeID, String displayLocaleID)
localeID
- the id of the locale whose script will be displayeddisplayLocaleID
- the id of the locale in which to display the name.
public static String getDisplayScript(String localeID, ULocale displayLocale)
localeID
- the id of the locale whose script will be displayed.displayLocale
- the locale in which to display the name.
public String getDisplayCountry()
DISPLAY
locale.
ULocale.Category.DISPLAY
public String getDisplayCountry(ULocale displayLocale)
displayLocale
- the locale in which to display the name.
public static String getDisplayCountry(String localeID, String displayLocaleID)
localeID
- the id of the locale whose country will be displayeddisplayLocaleID
- the id of the locale in which to display the name.
public static String getDisplayCountry(String localeID, ULocale displayLocale)
localeID
- the id of the locale whose country will be displayed.displayLocale
- the locale in which to display the name.
public String getDisplayVariant()
DISPLAY
locale.
ULocale.Category.DISPLAY
public String getDisplayVariant(ULocale displayLocale)
displayLocale
- the locale in which to display the name.
public static String getDisplayVariant(String localeID, String displayLocaleID)
localeID
- the id of the locale whose variant will be displayeddisplayLocaleID
- the id of the locale in which to display the name.
public static String getDisplayVariant(String localeID, ULocale displayLocale)
localeID
- the id of the locale whose variant will be displayed.displayLocale
- the locale in which to display the name.
public static String getDisplayKeyword(String keyword)
DISPLAY
locale.
keyword
- the keyword to be displayed.
getKeywords()
,
ULocale.Category.DISPLAY
public static String getDisplayKeyword(String keyword, String displayLocaleID)
keyword
- the keyword to be displayed.displayLocaleID
- the id of the locale in which to display the keyword.
getKeywords(String)
public static String getDisplayKeyword(String keyword, ULocale displayLocale)
keyword
- the keyword to be displayed.displayLocale
- the locale in which to display the keyword.
getKeywords(String)
public String getDisplayKeywordValue(String keyword)
DISPLAY
locale.
keyword
- the keyword whose value is to be displayed.
ULocale.Category.DISPLAY
public String getDisplayKeywordValue(String keyword, ULocale displayLocale)
keyword
- the keyword whose value is to be displayed.displayLocale
- the locale in which to display the value.
public static String getDisplayKeywordValue(String localeID, String keyword, String displayLocaleID)
localeID
- the id of the locale whose keyword value is to be displayed.keyword
- the keyword whose value is to be displayed.displayLocaleID
- the id of the locale in which to display the value.
public static String getDisplayKeywordValue(String localeID, String keyword, ULocale displayLocale)
localeID
- the id of the locale whose keyword value is to be displayed.keyword
- the keyword whose value is to be displayed.displayLocale
- the id of the locale in which to display the value.
public String getDisplayName()
DISPLAY
locale.
ULocale.Category.DISPLAY
public String getDisplayName(ULocale displayLocale)
displayLocale
- the locale in which to display the locale name.
public static String getDisplayName(String localeID, String displayLocaleID)
localeID
- the locale whose name is to be displayed.displayLocaleID
- the id of the locale in which to display the locale name.
public static String getDisplayName(String localeID, ULocale displayLocale)
localeID
- the locale whose name is to be displayed.displayLocale
- the locale in which to display the locale name.
public String getDisplayNameWithDialect()
DISPLAY
locale.
If a dialect name is present in the locale data, then it is returned.
ULocale.Category.DISPLAY
public String getDisplayNameWithDialect(ULocale displayLocale)
displayLocale
- the locale in which to display the locale name.
public static String getDisplayNameWithDialect(String localeID, String displayLocaleID)
localeID
- the locale whose name is to be displayed.displayLocaleID
- the id of the locale in which to display the locale name.
public static String getDisplayNameWithDialect(String localeID, ULocale displayLocale)
localeID
- the locale whose name is to be displayed.displayLocale
- the locale in which to display the locale name.
public String getCharacterOrientation()
public String getLineOrientation()
public static ULocale acceptLanguage(String acceptLanguageList, ULocale[] availableLocales, boolean[] fallback)
acceptLanguageList
- list in HTTP "Accept-Language:" format of acceptable localesavailableLocales
- list of available locales. One of these will be returned.fallback
- if non-null, a 1-element array containing a boolean to be set with
the fallback status
public static ULocale acceptLanguage(ULocale[] acceptLanguageList, ULocale[] availableLocales, boolean[] fallback)
acceptLanguageList
- list of acceptable localesavailableLocales
- list of available locales. One of these will be returned.fallback
- if non-null, a 1-element array containing a boolean to be set with
the fallback status
public static ULocale acceptLanguage(String acceptLanguageList, boolean[] fallback)
acceptLanguageList
- list in HTTP "Accept-Language:" format of acceptable localesfallback
- if non-null, a 1-element array containing a boolean to be set with
the fallback status
public static ULocale acceptLanguage(ULocale[] acceptLanguageList, boolean[] fallback)
acceptLanguageList
- ordered array of acceptable locales (preferred are listed first)fallback
- if non-null, a 1-element array containing a boolean to be set with
the fallback status
public static ULocale addLikelySubtags(ULocale loc)
loc
- The ULocale to maximize
public static ULocale minimizeSubtags(ULocale loc)
http://www.unicode.org/reports/tr35/#Likely_SubtagsIf the provided ULocale instance is already in the minimal form, or there is no data available for minimization, it will be returned. Since the minimization algorithm relies on proper maximization, see the comments for addLikelySubtags for reasons why there might not be any data. Examples:
"en_Latn_US" minimizes to "en" "de_Latn_US" minimizes to "de" "sr_Cyrl_RS" minimizes to "sr" "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the script, and minimizing to "zh" would imply "zh_Hans_CN".)
loc
- The ULocale to minimize
public String getExtension(char key)
[0-9A-Za-z]
. Keys are case-insensitive, so
for example 'z' and 'Z' represent the same extension.
key
- the extension key
IllegalArgumentException
- if key is not well-formedPRIVATE_USE_EXTENSION
,
UNICODE_LOCALE_EXTENSION
public Set<Character> getExtensionKeys()
public Set<String> getUnicodeLocaleAttributes()
public String getUnicodeLocaleType(String key)
key
- the Unicode locale key
IllegalArgumentException
- if the key is not well-formed
NullPointerException
- if key
is nullpublic Set<String> getUnicodeLocaleKeys()
public String toLanguageTag()
If this ULocale
has a language, script, country, or
variant that does not satisfy the IETF BCP 47 language tag
syntax requirements, this method handles these fields as
described below:
Language: If language is empty, or not well-formed (for example "a" or "e2"), it will be emitted as "und" (Undetermined).
Script: If script is not well-formed (for example "12" or "Latin"), it will be omitted.
Country: If country is not well-formed (for example "12" or "USA"), it will be omitted.
Variant: If variant is well-formed, each sub-segment (delimited by '-' or '_') is emitted as a subtag. Otherwise:
[0-9a-zA-Z]{1,8}
(for example "WIN" or "Oracle_JDK_Standard_Edition"), the first
ill-formed sub-segment and all following will be appended to
the private use subtag. The first appended subtag will be
"lvariant", followed by the sub-segments in order, separated by
hyphen. For example, "x-lvariant-WIN",
"Oracle-x-lvariant-JDK-Standard-Edition".
[0-9a-zA-Z]{1,8}
, the variant will be truncated
and the problematic sub-segment and all following sub-segments
will be omitted. If the remainder is non-empty, it will be
emitted as a private use subtag as above (even if the remainder
turns out to be well-formed). For example,
"Solaris_isjustthecoolestthing" is emitted as
"x-lvariant-Solaris", not as "solaris".Note: Although the language tag created by this method is well-formed (satisfies the syntax requirements defined by the IETF BCP 47 specification), it is not necessarily a valid BCP 47 language tag. For example,
new Locale("xx", "YY").toLanguageTag();will return "xx-YY", but the language subtag "xx" and the region subtag "YY" are invalid because they are not registered in the IANA Language Subtag Registry.
forLanguageTag(String)
public static ULocale forLanguageTag(String languageTag)
If the specified language tag contains any ill-formed subtags,
the first such subtag and all following subtags are ignored. Compare
to ULocale.Builder.setLanguageTag(java.lang.String)
which throws an exception
in this case.
The following conversions are performed:
ULocale loc; loc = ULocale.forLanguageTag("en-US-x-lvariant-icu4j); loc.getVariant(); // returns "ICU4J" loc.getExtension('x'); // returns null loc = Locale.forLanguageTag("de-icu4j-x-URP-lvariant-Abc-Def"); loc.getVariant(); // returns "ICU4J_ABC_DEF" loc.getExtension('x'); // returns "urp"
ULocale.forLanguageTag("ar-aao").getLanguage(); // returns "aao" ULocale.forLanguageTag("en-abc-def-us").toString(); // returns "abc_US"
This implements the 'Language-Tag' production of BCP47, and so supports grandfathered (regular and irregular) as well as private use language tags. Stand alone private use tags are represented as empty language and extension 'x-whatever', and grandfathered tags are converted to their canonical replacements where they exist.
Grandfathered tags with canonical replacements are as follows:
grandfathered tag | modern replacement | |
---|---|---|
art-lojban | jbo | |
i-ami | ami | |
i-bnn | bnn | |
i-hak | hak | |
i-klingon | tlh | |
i-lux | lb | |
i-navajo | nv | |
i-pwn | pwn | |
i-tao | tao | |
i-tay | tay | |
i-tsu | tsu | |
no-bok | nb | |
no-nyn | nn | |
sgn-BE-FR | sfb | |
sgn-BE-NL | vgt | |
sgn-CH-DE | sgg | |
zh-guoyu | cmn | |
zh-hakka | hak | |
zh-min-nan | nan | |
zh-xiang | hsn |
Grandfathered tags with no modern replacement will be converted as follows:
grandfathered tag | converts to | |
---|---|---|
cel-gaulish | xtg-x-cel-gaulish | |
en-GB-oed | en-GB-x-oed | |
i-default | en-x-i-default | |
i-enochian | und-x-i-enochian | |
i-mingo | see-x-i-mingo | |
zh-min | nan-x-zh-min |
For a list of all grandfathered tags, see the IANA Language Subtag Registry (search for "Type: grandfathered").
Note: there is no guarantee that toLanguageTag
and forLanguageTag
will round-trip.
languageTag
- the language tag
NullPointerException
- if languageTag
is null
toLanguageTag()
,
ULocale.Builder.setLanguageTag(String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |