Spec-Zone .ru
спецификации, руководства, описания, API
|
The Java SE 7 release conforms to the IETF BCP 47 standard, which supports adding extensions to a Locale
. Any single character can be used to denote an extension, but there are two predefined extension codes: 'u'
specifies a Unicode locale extension, and 'x'
specifies a private use extension.
Unicode locale extensions are defined by the Unicode
An extension is specified as a key/value pair, where the key is a single character (typically 'u'
or 'x'
). A well-formed value has the following format:
SUBTAG ('-' SUBTAG)*
In this format:
SUBTAG = [0-9a-zA-Z]{2,8} For key='u' SUBTAG = [0-9a-zA-Z]{1,8} For key='x'
Note that a single-character value is allowed for the private use extension. However, there is a 2-character minimum for values in the Unicode locale extension.
Extension strings are case-insensitive, but the Locale
class maps all keys and values to lowercase.
The
getExtensionKeys()
Locale
. The
getExtension(key)
As previously mentioned, a Unicode locale extension is specified by the 'u'
key code or the UNICODE_LOCALE_EXTENSION
constant. The value itself is also specified by a key/type pair. Legal values are defined in the
Key Code | Description |
---|---|
ca | calendar algorithm |
co | collation type |
ka | collation parameters |
cu | currency type |
nu | number type |
va | common variant type |
Specifying a Unicode locale extension, such as number format, does not guarantee that the locale services for the underlying platform will honor that request.
The following table shows some examples of key/type pairs for a Unicode locale extension.
Key/Type pair | Description |
---|---|
ca-buddhist | Thai Buddhist calendar |
co-pinyin | Pinyin ordering for Latin |
cu-usd | U.S. dollars |
nu-jpanfin | Japanese financial numerals |
tz-aldav | Europe/Andorra |
The following string represents the German language locale for the country of Germany using a phonebook style of ordering for the Linux platform. This example also contains an attribute named "email"
.
de-DE-u-email-co-phonebk-x-linux
The following Locale
methods can be used to access information about the Unicode locale extensionss. These methods are described using the previous German locale example.
getUnicodeLocaleKeys()
"co"
.getUnicodeLocaleType(String)
getUnicodeLocaleType("co")
for the German example would return the string "phonebk"
.getUnicodeLocaleAttributes()
"email"
.The private use extension, specified by the 'x'
key code or the PRIVATE_USE_EXTENSION
constant, can be anything, as long as the value is well formed.
The following are examples of possible private use extensions:
x-jdk-1-7 x-linux