public enum LocaleCode extends Enum<LocaleCode>
The list of the enum entries was generated based on the output from
Locale.getAvailableLocales()
of Java SE 7, but locales whose
format do not match either 'xx' or 'xx-XX' were excluded.
// List all the locale codes. for (LocaleCode code : LocaleCode.values()) { String language = code.getLanguage()
.getName()
; String country = code.getCountry()
!= null ? code.getCountry()
.getName()
: null; // For example, "[de-DE] German, Germany" is printed. System.out.format("[%s] %s, %s\n", code, language, country); } // Get a LocaleCode instance in various ways. LocaleCode code; code = LocaleCode.getByCode
("en-GB"); code = LocaleCode.getByCode
("es", "ES"); code = LocaleCode.getByLocale
(new Locale("pt", "BR")); // Convert to a Locale instance. Locale locale = LocaleCode.en
.toLocale()
; // toLocale() of some LocaleCode instances does not create // a new Locale instance but returns a static variable of // Locale class instead. SeetoLocale()
for details. if (locale == Locale.ENGLISH) { System.out.println("Locale.en.toLocale() returned Locale.ENGLISH"); } // Get a list of LocaleCode instances whose language is Arabic. List<LocaleCode> list = LocaleCode.getByLanguage
(LanguageCode.ar
); // Get a list of LocaleCode instances whose country is Switzerland. list = LocaleCode.getByCountry
(CountryCode.CH
);
Enum Constant and Description |
---|
ar
|
ar_AE
|
ar_BH
|
ar_DZ
|
ar_EG
|
ar_IQ
|
ar_JO
|
ar_KW
|
ar_LB
|
ar_LY
|
ar_MA
|
ar_OM
|
ar_QA
|
ar_SA
|
ar_SD
|
ar_SY
|
ar_TN
|
ar_YE
|
be
|
be_BY
|
bg
|
bg_BG
|
ca
|
ca_ES
|
cs
|
cs_CZ
|
da
|
da_DK
|
de
|
de_AT
|
de_CH
|
de_DE
|
de_LU
|
el
|
el_CY
|
el_GR
|
en
|
en_AU
|
en_CA
|
en_GB
|
en_HK
|
en_IE
|
en_IN
|
en_MT
|
en_NZ
|
en_PH
|
en_SG
|
en_US
|
en_ZA
|
es
|
es_AR
|
es_BO
|
es_CL
|
es_CO
|
es_CR
|
es_DO
|
es_EC
|
es_ES
|
es_GT
|
es_HN
|
es_MX
|
es_NI
|
es_PA
|
es_PE
|
es_PR
|
es_PY
|
es_SV
|
es_US
|
es_UY
|
es_VE
|
et
|
et_EE
|
fa
|
fa_IR
|
fi
|
fi_FI
|
fr
|
fr_BE
|
fr_CA
|
fr_CH
|
fr_FR
|
fr_LU
|
ga
|
ga_IE
|
he
|
he_IL
|
hi_IN
|
hr
|
hr_HR
|
hu
|
hu_HU
|
id
|
id_ID
|
is
|
is_IS
|
it
|
it_CH
|
it_IT
|
ja
|
ja_JP
|
kk_KZ
|
ko
|
ko_KR
|
lt
|
lt_LT
|
lv
|
lv_LV
|
mk
|
mk_MK
|
ms
|
ms_MY
|
mt
|
mt_MT
|
nb
|
nb_NO
|
nl
|
nl_BE
|
nl_NL
|
nn_NO
|
no
|
no_NO
Deprecated.
nb_NO should be used. |
pl
|
pl_PL
|
pt
|
pt_BR
|
pt_PT
|
ro
|
ro_MD
|
ro_RO
|
ru
|
ru_KZ
|
ru_RU
|
se
|
se_NO
|
sk
|
sk_SK
|
sl
|
sl_SI
|
sq
|
sq_AL
|
sr
|
sr_BA
|
sr_CS
|
sr_ME
|
sr_RS
|
sv
|
sv_SE
|
th
|
th_TH
|
tr
|
tr_TR
|
uk
|
uk_UA
|
undefined
|
vi
|
vi_VN
|
zh
|
zh_CN
|
zh_HK
|
zh_SG
|
zh_TW
|
Modifier and Type | Method and Description |
---|---|
static LocaleCode |
getByCode(String code)
Get a
LocaleCode instance that corresponds to the given code. |
static LocaleCode |
getByCode(String code,
boolean caseSensitive)
Get a
LocaleCode instance that corresponds to the given code. |
static LocaleCode |
getByCode(String language,
String country)
Get a
LocaleCode instance that corresponds to the given pair of
language code and country code. |
static LocaleCode |
getByCode(String language,
String country,
boolean caseSensitive)
Get a
LocaleCode instance that corresponds to the given pair of
language code and country code. |
static LocaleCode |
getByCodeIgnoreCase(String code)
Get a
LocaleCode instance that corresponds to the given code. |
static LocaleCode |
getByCodeIgnoreCase(String language,
String country)
Get a
LocaleCode instance that corresponds to the given pair of
language code and country code. |
static List<LocaleCode> |
getByCountry(CountryCode country)
Get a list of
LocaleCode instances whose country matches the given one. |
static List<LocaleCode> |
getByCountry(String country)
Get a list of
LocaleCode instances whose country matches the given one. |
static List<LocaleCode> |
getByCountry(String country,
boolean caseSensitive)
Get a list of
LocaleCode instances whose country matches the given one. |
static List<LocaleCode> |
getByCountryIgnoreCase(String country)
Get a list of
LocaleCode instances whose country matches the given one. |
static List<LocaleCode> |
getByLanguage(LanguageCode language)
Get a list of
LocaleCode instances whose language matches the given one. |
static List<LocaleCode> |
getByLanguage(String language)
Get a list of
LocaleCode instances whose language matches the given one. |
static List<LocaleCode> |
getByLanguage(String language,
boolean caseSensitive)
Get a list of
LocaleCode instances whose language matches the given one. |
static List<LocaleCode> |
getByLanguageIgnoreCase(String language)
Get a list of
LocaleCode instances whose language matches the given one. |
static LocaleCode |
getByLocale(Locale locale)
Get a
LocaleCode instance that corresponds to the given
Locale instance. |
CountryCode |
getCountry()
Get the country code.
|
LanguageCode |
getLanguage()
Get the language code.
|
Locale |
toLocale()
Convert this
LocaleCode instance to a Locale instance. |
String |
toString()
Get the string representation of this locale code.
|
static LocaleCode |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static LocaleCode[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final LocaleCode undefined
public static final LocaleCode ar
public static final LocaleCode ar_AE
public static final LocaleCode ar_BH
public static final LocaleCode ar_DZ
public static final LocaleCode ar_EG
public static final LocaleCode ar_IQ
public static final LocaleCode ar_JO
public static final LocaleCode ar_KW
public static final LocaleCode ar_LB
public static final LocaleCode ar_LY
public static final LocaleCode ar_MA
public static final LocaleCode ar_OM
public static final LocaleCode ar_QA
public static final LocaleCode ar_SA
public static final LocaleCode ar_SD
public static final LocaleCode ar_SY
public static final LocaleCode ar_TN
public static final LocaleCode ar_YE
public static final LocaleCode be
public static final LocaleCode be_BY
public static final LocaleCode bg
public static final LocaleCode bg_BG
public static final LocaleCode ca
public static final LocaleCode ca_ES
public static final LocaleCode cs
public static final LocaleCode cs_CZ
public static final LocaleCode da
public static final LocaleCode da_DK
public static final LocaleCode de
public static final LocaleCode de_AT
public static final LocaleCode de_CH
public static final LocaleCode de_DE
public static final LocaleCode de_LU
public static final LocaleCode el
public static final LocaleCode el_CY
public static final LocaleCode el_GR
public static final LocaleCode en
public static final LocaleCode en_AU
public static final LocaleCode en_CA
public static final LocaleCode en_GB
public static final LocaleCode en_HK
public static final LocaleCode en_IE
public static final LocaleCode en_IN
public static final LocaleCode en_MT
public static final LocaleCode en_NZ
public static final LocaleCode en_PH
public static final LocaleCode en_SG
public static final LocaleCode en_US
public static final LocaleCode en_ZA
public static final LocaleCode es
public static final LocaleCode es_AR
public static final LocaleCode es_BO
public static final LocaleCode es_CL
public static final LocaleCode es_CO
public static final LocaleCode es_CR
public static final LocaleCode es_DO
public static final LocaleCode es_EC
public static final LocaleCode es_ES
public static final LocaleCode es_GT
public static final LocaleCode es_HN
public static final LocaleCode es_MX
public static final LocaleCode es_NI
public static final LocaleCode es_PA
public static final LocaleCode es_PE
public static final LocaleCode es_PR
public static final LocaleCode es_PY
public static final LocaleCode es_SV
public static final LocaleCode es_US
public static final LocaleCode es_UY
public static final LocaleCode es_VE
public static final LocaleCode et
public static final LocaleCode et_EE
public static final LocaleCode fa
public static final LocaleCode fa_IR
public static final LocaleCode fi
public static final LocaleCode fi_FI
public static final LocaleCode fr
public static final LocaleCode fr_BE
public static final LocaleCode fr_CA
public static final LocaleCode fr_CH
public static final LocaleCode fr_FR
public static final LocaleCode fr_LU
public static final LocaleCode ga
public static final LocaleCode ga_IE
public static final LocaleCode he
public static final LocaleCode he_IL
public static final LocaleCode hi_IN
public static final LocaleCode hr
public static final LocaleCode hr_HR
public static final LocaleCode hu
public static final LocaleCode hu_HU
public static final LocaleCode id
public static final LocaleCode id_ID
public static final LocaleCode is
public static final LocaleCode is_IS
public static final LocaleCode it
public static final LocaleCode it_CH
public static final LocaleCode it_IT
public static final LocaleCode ja
public static final LocaleCode ja_JP
public static final LocaleCode kk_KZ
public static final LocaleCode ko
public static final LocaleCode ko_KR
public static final LocaleCode lt
public static final LocaleCode lt_LT
public static final LocaleCode lv
public static final LocaleCode lv_LV
public static final LocaleCode mk
public static final LocaleCode mk_MK
public static final LocaleCode ms
public static final LocaleCode ms_MY
public static final LocaleCode mt
public static final LocaleCode mt_MT
public static final LocaleCode nb
public static final LocaleCode nb_NO
public static final LocaleCode nl
public static final LocaleCode nl_BE
public static final LocaleCode nl_NL
public static final LocaleCode nn_NO
public static final LocaleCode no
public static final LocaleCode no_NO
nb_NO
should be used.public static final LocaleCode pl
public static final LocaleCode pl_PL
public static final LocaleCode pt
public static final LocaleCode pt_BR
public static final LocaleCode pt_PT
public static final LocaleCode ro
public static final LocaleCode ro_MD
public static final LocaleCode ro_RO
public static final LocaleCode ru
public static final LocaleCode ru_KZ
public static final LocaleCode ru_RU
public static final LocaleCode se
public static final LocaleCode se_NO
public static final LocaleCode sk
public static final LocaleCode sk_SK
public static final LocaleCode sl
public static final LocaleCode sl_SI
public static final LocaleCode sq
public static final LocaleCode sq_AL
public static final LocaleCode sr
public static final LocaleCode sr_BA
public static final LocaleCode sr_CS
public static final LocaleCode sr_ME
public static final LocaleCode sr_RS
public static final LocaleCode sv
public static final LocaleCode sv_SE
public static final LocaleCode th
public static final LocaleCode th_TH
public static final LocaleCode tr
public static final LocaleCode tr_TR
public static final LocaleCode uk
public static final LocaleCode uk_UA
public static final LocaleCode vi
public static final LocaleCode vi_VN
public static final LocaleCode zh
public static final LocaleCode zh_CN
public static final LocaleCode zh_HK
public static final LocaleCode zh_SG
public static final LocaleCode zh_TW
public static LocaleCode[] values()
for (LocaleCode c : LocaleCode.values()) System.out.println(c);
public static LocaleCode valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic LanguageCode getLanguage()
public CountryCode getCountry()
LocaleCode.en
.getCountry() returns null.public String toString()
-
country
where language is an ISO 639-1 code and country is an ISO 3166-1 alpha-2 code.
toString
in class Enum<LocaleCode>
public Locale toLocale()
LocaleCode
instance to a Locale
instance.
In most cases, this method creates a new Locale
instance
every time it is called, but some LocaleCode
instances
return their corresponding entries in Locale
class.
For example, LocaleCode.it
always returns
Locale.ITALIAN
.
The table below lists LocaleCode
entries whose toLocale()
does not create a new Locale
instance but returns an entry in
Locale
class.
In addition, toLocale()
of LocaleCode.undefined
behaves a bit differently. It returns
Locale.ROOT
when it is available (i.e. when
the version of Java SE is 1.6 or higher). Otherwise, it returns
a Locale
instance whose language and country are empty
strings. Even in the latter case, the same instance is returned
on every call.
Locale
instance that matches this LocaleCode
.public static LocaleCode getByCode(String code)
LocaleCode
instance that corresponds to the given code.
This method just calls getByCode
(code, true)
.
Note that the behavior has changed since the version 1.13. In the older versions,
this method was an alias of getByCode(code, false)
.
code
- A locale code.LocaleCode
instance, or null
if not found.getByCode(String, boolean)
public static LocaleCode getByCodeIgnoreCase(String code)
LocaleCode
instance that corresponds to the given code.
This method just calls getByCode
(code, false)
.
code
- A locale code.LocaleCode
instance, or null
if not found.getByCode(String, boolean)
public static LocaleCode getByCode(String code, boolean caseSensitive)
LocaleCode
instance that corresponds to the given code.
The format of the code should be either of the following:
-
country
where language is an ISO 639-1 code
and country is an ISO 3166-1
alpha-2 code. The separator between language and
country should be a hyphen (-
) or an underscore
(_
).
Note that if the language part of the given code is one of legacy ones { "iw", "ji" and "in" }, it is regarded as its newer official counterpart { "he", "yi" and "id" }, respectively.
code
- A locale code.caseSensitive
- If true
, the language part of the given code must be
lower-case and the country part, if not null
, must be
upper-case. If false, this method internally canonicalizes
the given code and then performs search.LocaleCode
instance, or null
if not found.public static LocaleCode getByCode(String language, String country)
LocaleCode
instance that corresponds to the given pair of
language code and country code.
This method just calls getByCode
(language, country, true)
.
Note that the behavior has changed since the version 1.13.
In the older versions, this method was an alias of getByCode(language, country, false)
.
language
- ISO 639-1 language code. Or "undefined" (case
sensitive). If the given language code is one of legacy
ones { "iw", "ji" and "in" }, it is regarded as its newer
official counterpart { "he", "yi" and "id" }, respectively.country
- ISO 3166-1 alpha-2 country code. Or "UNDEFINED"
(case sensitive).LocaleCode
, or null
if not found.getByCode(String, String, boolean)
public static LocaleCode getByCodeIgnoreCase(String language, String country)
LocaleCode
instance that corresponds to the given pair of
language code and country code.
This method just calls getByCode
(language, country, false)
.
language
- ISO 639-1 language code. Or "undefined" (case
insensitive). If the given language code is one of legacy
ones { "iw", "ji" and "in" }, it is regarded as its newer
official counterpart { "he", "yi" and "id" }, respectively.country
- ISO 3166-1 alpha-2 country code. Or "UNDEFINED"
(case insensitive).LocaleCode
, or null
if not found.getByCode(String, String, boolean)
public static LocaleCode getByCode(String language, String country, boolean caseSensitive)
LocaleCode
instance that corresponds to the given pair of
language code and country code.
If language
is "undefined" and if country
is null
or "UNDEFINED", LocaleCode.undefined
is returned.
language
- ISO 639-1 language code. Or "undefined".
If the given language code is one of legacy ones { "iw",
"ji" and "in" }, it is regarded as its newer official
counterpart { "he", "yi" and "id" }, respectively.country
- ISO 3166-1 alpha-2 country code. Or "UNDEFINED".caseSensitive
- If true
, the given language code must be lower-case and
the given country code, if not null
, must be upper-case.
If false
, this method internally canonicalizes the given
codes and then performs search.LocaleCode
, or null
if not found.public static LocaleCode getByLocale(Locale locale)
LocaleCode
instance that corresponds to the given
Locale
instance.locale
- A Locale
instance.LocaleCode
instance, or null
if not found.
When the value returned by getLanguage()
method of the given instance is null
or an empty string and
the value returned by getCountry()
method
of the given instance is null
or an empty string,
LocaleCode.undefined
is returned.public static List<LocaleCode> getByLanguage(String language)
LocaleCode
instances whose language matches the given one.
This method is an alias of getByLanguage
(language, true)
.
Note that the behavior has changed since the version 1.13. In the older versions,
this method was an alias of getByLanguage(language, false)
.
language
- Language code. ISO 639 alpha-2 or alpha-3.LocaleCode
instances. If there is no LocaleCode
instance whose language matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByLanguageIgnoreCase(String language)
LocaleCode
instances whose language matches the given one.
This method is an alias of getByLanguage
(language, false)
.
language
- Language code. ISO 639 alpha-2 or alpha-3.LocaleCode
instances. If there is no LocaleCode
instance whose language matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByLanguage(String language, boolean caseSensitive)
LocaleCode
instances whose language matches the given one.
This method is an alias of getByLanguage
(
LanguageCode
.
getByCode
(language, caseSensitive))
.
language
- Language code. ISO 639 alpha-2 or alpha-3.caseSensitive
- If true
, the given code should consist of lowercase letters only.
If false
, case is ignored.LocaleCode
instances. If there is no LocaleCode
instance whose language matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByLanguage(LanguageCode language)
LocaleCode
instances whose language matches the given one.language
- LanguageCode
instance that represents a language.LocaleCode
instances. If there is no LocaleCode
instance whose language matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByCountry(String country)
LocaleCode
instances whose country matches the given one.
This method is an alias of getByCountry
(country, true)
.
Note that the behavior has changed since the version 1.13. In the older versions,
this method was an alias of getByCountry(country, false)
.
country
- Country code. ISO 3166-1 alpha-2 or alpha-3.LocaleCode
instances. If there is no LocaleCode
instance whose country matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByCountryIgnoreCase(String country)
LocaleCode
instances whose country matches the given one.
This method is an alias of getByCountry
(country, false)
.
country
- Country code. ISO 3166-1 alpha-2 or alpha-3.LocaleCode
instances. If there is no LocaleCode
instance whose country matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByCountry(String country, boolean caseSensitive)
LocaleCode
instances whose country matches the given one.
This method is an alias of getByCountry
(
CountryCode
.
getByCode
(country, caseSensitive))
.
country
- Country code. ISO 3166-1 alpha-2 or alpha-3.caseSensitive
- If true
, the given code should consist of uppercase letters only.
If false
, case is ignored.LocaleCode
instances. If there is no LocaleCode
instance whose country matches the given one, the size of the returned
list is zero.public static List<LocaleCode> getByCountry(CountryCode country)
LocaleCode
instances whose country matches the given one.country
- CountryCode
instance that represents a country.LocaleCode
instances. If there is no LocaleCode
instance whose country matches the given one, the size of the returned
list is zero.Copyright © 2021. All rights reserved.