DthingApi
|
Public Member Functions | |
Locale (String language) | |
Locale (String language, String country) | |
Locale (String language, String country, String variant) | |
Object | clone () |
boolean | equals (Object object) |
String | getCountry () |
final String | getDisplayCountry () |
String | getDisplayCountry (Locale locale) |
final String | getDisplayLanguage () |
String | getDisplayLanguage (Locale locale) |
final String | getDisplayName () |
String | getDisplayName (Locale locale) |
final String | getDisplayVariant () |
String | getDisplayVariant (Locale locale) |
String | getISO3Country () |
String | getISO3Language () |
String | getLanguage () |
String | getVariant () |
synchronized int | hashCode () |
final String | toString () |
Static Public Member Functions | |
static Locale [] | getAvailableLocales () |
static Locale | getDefault () |
static String [] | getISOCountries () |
static String [] | getISOLanguages () |
static synchronized void | setDefault (Locale locale) |
Static Public Attributes | |
static final Locale | CANADA = new Locale(true, "en", "CA") |
static final Locale | CANADA_FRENCH = new Locale(true, "fr", "CA") |
static final Locale | CHINA = new Locale(true, "zh", "CN") |
static final Locale | CHINESE = new Locale(true, "zh", "") |
static final Locale | ENGLISH = new Locale(true, "en", "") |
static final Locale | FRANCE = new Locale(true, "fr", "FR") |
static final Locale | FRENCH = new Locale(true, "fr", "") |
static final Locale | GERMAN = new Locale(true, "de", "") |
static final Locale | GERMANY = new Locale(true, "de", "DE") |
static final Locale | ITALIAN = new Locale(true, "it", "") |
static final Locale | ITALY = new Locale(true, "it", "IT") |
static final Locale | JAPAN = new Locale(true, "ja", "JP") |
static final Locale | JAPANESE = new Locale(true, "ja", "") |
static final Locale | KOREA = new Locale(true, "ko", "KR") |
static final Locale | KOREAN = new Locale(true, "ko", "") |
static final Locale | PRC = new Locale(true, "zh", "CN") |
static final Locale | ROOT = new Locale(true, "", "") |
static final Locale | SIMPLIFIED_CHINESE = new Locale(true, "zh", "CN") |
static final Locale | TAIWAN = new Locale(true, "zh", "TW") |
static final Locale | TRADITIONAL_CHINESE = new Locale(true, "zh", "TW") |
static final Locale | UK = new Locale(true, "en", "GB") |
static final Locale | US = new Locale(true, "en", "US") |
represents a language/country/variant combination. Locales are used to alter the presentation of information such as numbers or dates to suit the conventions in the region they describe.
The language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1. The country codes are two-letter uppercase ISO country codes (such as "US") as defined by ISO 3166-1. The variant codes are unspecified.
Note that Java uses several deprecated two-letter codes. The Hebrew ("he") language code is rewritten as "iw", Indonesian ("id") as "in", and Yiddish ("yi") as "ji". This rewriting happens even if you construct your own
object, not just for instances returned by the various lookup methods.
This class' constructors do no error checking. You can create a
for languages and countries that don't exist, and you can create instances for combinations that don't exist (such as "de_US" for "German as spoken in the US").
Note that locale data is not necessarily available for any of the locales pre-defined as constants in this class except for en_US, which is the only locale Java guarantees is always available.
It is also a mistake to assume that all devices have the same locales available. A device sold in the US will almost certainly support en_US and es_US, but not necessarily any locales with the same language but different countries (such as en_GB or es_ES), nor any locales for other languages (such as de_DE). The opposite may well be true for a device sold in Europe.
You can use Locale#getDefault to get an appropriate locale for the user of the device you're running on, or Locale#getAvailableLocales to get a list of all the locales available on the device you're running on.
Note that locale data comes solely from ICU. User-supplied locale service providers (using the
or
mechanisms) are not supported.
Here are the versions of ICU (and the corresponding CLDR and Unicode versions) used in various Android releases:
cupcake/donut/eclair | ICU 3.8 | CLDR 1.5 | Unicode 5.0 |
froyo | ICU 4.2 | CLDR 1.7 | Unicode 5.1 |
gingerbread/honeycomb | ICU 4.4 | CLDR 1.8 | Unicode 5.2 |
ice cream sandwich | ICU 4.6 | CLDR 1.9 | Unicode 6.0 |
Note that there are many convenience methods that automatically use the default locale, but using them may lead to subtle bugs.
The default locale is appropriate for tasks that involve presenting data to the user. In this case, you want to use the user's date/time formats, number formats, rules for conversion to lowercase, and so on. In this case, it's safe to use the convenience methods.
The default locale is not appropriate for machine-readable output. The best choice there is usually
– this locale is guaranteed to be available on all devices, and the fact that it has no surprising special cases and is frequently used (especially for computer-computer communication) means that it tends to be the most efficient choice too.
A common mistake is to implicitly use the default locale when producing output meant to be machine-readable. This tends to work on the developer's test devices (especially because so many developers use en_US), but fails when run on a device whose user is in a more complex locale.
For example, if you're formatting integers some locales will use non-ASCII decimal digits. As another example, if you're formatting floating-point numbers some locales will use
as the decimal point and
for digit grouping. That's correct for human-readable output, but likely to cause problems if presented to another computer (Double#parseDouble can't parse such a number, for example). You should also be wary of the String#toLowerCase and String#toUpperCase overloads that don't take a
: in Turkey, for example, the characters
and
won't be converted to
and
. This is the correct behavior for Turkish text (such as user input), but inappropriate for, say, HTTP headers.
|
inline |
Constructs a new
using the specified language.
|
inline |
Constructs a new
using the specified language and country codes.
|
inline |
Constructs a new
using the specified language, country, and variant codes.
|
inline |
Returns true if
is a locale with the same language, country and variant.
|
inlinestatic |
Returns the system's installed locales. This array always includes
, and usually several others. Most locale-sensitive classes offer their own
method, which should be preferred over this general purpose method.
|
inline |
Returns the country code for this locale, or
if this locale doesn't correspond to a specific country.
|
inlinestatic |
Returns the user's preferred locale. This may have been overridden for this process with setDefault.
Since the user's locale changes dynamically, avoid caching this value. Instead, use this method to look it up for each use.
|
inline |
|
inline |
Returns the name of this locale's country, localized to
. Returns the empty string if this locale does not correspond to a specific country.
|
inline |
|
inline |
Returns the name of this locale's language, localized to
. If the language name is unknown, the language code is returned.
|
inline |
|
inline |
Returns this locale's language name, country name, and variant, localized to
. The exact output form depends on whether this locale corresponds to a specific language, country and variant.
For example:
|
inline |
Returns the full variant name in the default
for the variant code of this
. If there is no matching variant name, the variant code is returned.
|
inline |
Returns the full variant name in the specified
for the variant code of this
. If there is no matching variant name, the variant code is returned.
|
inline |
Returns the three letter ISO country code which corresponds to the country code for this
.
|
inline |
Returns the three letter ISO language code which corresponds to the language code for this
.
|
inlinestatic |
Returns an array of strings containing all the two-letter ISO country codes that can be used as the country code when constructing a
.
|
inlinestatic |
Returns an array of strings containing all the two-letter ISO language codes that can be used as the language code when constructing a
.
|
inline |
Returns the language code for this
or the empty string if no language was set.
|
inline |
Returns the variant code for this
or an empty
if no variant was set.
|
inlinestatic |
Overrides the default locale. This does not affect system configuration, and attempts to override the system-provided default locale may themselves be overridden by actual changes to the system configuration. Code that calls this method is usually incorrect, and should be fixed by passing the appropriate locale to each locale-sensitive method that's called.
|
inline |
Returns the string representation of this
. It consists of the language code, country code and variant separated by underscores. If the language is missing the string begins with an underscore. If the country is missing there are 2 underscores between the language and the variant. The variant cannot stand alone without a language and/or country code: in this case this method would return the empty string.
Examples: "en", "en_US", "_US", "en__POSIX", "en_US_POSIX"
Locale constant for en_CA.
Locale constant for fr_CA.
Locale constant for zh_CN.
Locale constant for fr_FR.
Locale constant for de_DE.
Locale constant for it_IT.
Locale constant for ja_JP.
Locale constant for ko_KR.
Locale constant for the root locale. The root locale has an empty language, country, and variant.
Locale constant for zh_CN.
Locale constant for zh_TW.
Locale constant for zh_TW.