Enum Class LocaleCode
- All Implemented Interfaces:
Serializable
,Comparable<LocaleCode>
,java.lang.constant.Constable
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
);
- Author:
- Takahiko Kawasaki
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic LocaleCode
Get aLocaleCode
instance that corresponds to the given code.static LocaleCode
Get aLocaleCode
instance that corresponds to the given code.static LocaleCode
Get aLocaleCode
instance that corresponds to the given pair of language code and country code.static LocaleCode
Get aLocaleCode
instance that corresponds to the given pair of language code and country code.static LocaleCode
getByCodeIgnoreCase
(String code) Get aLocaleCode
instance that corresponds to the given code.static LocaleCode
getByCodeIgnoreCase
(String language, String country) Get aLocaleCode
instance that corresponds to the given pair of language code and country code.static List<LocaleCode>
getByCountry
(CountryCode country) Get a list ofLocaleCode
instances whose country matches the given one.static List<LocaleCode>
getByCountry
(String country) Get a list ofLocaleCode
instances whose country matches the given one.static List<LocaleCode>
getByCountry
(String country, boolean caseSensitive) Get a list ofLocaleCode
instances whose country matches the given one.static List<LocaleCode>
getByCountryIgnoreCase
(String country) Get a list ofLocaleCode
instances whose country matches the given one.static List<LocaleCode>
getByLanguage
(LanguageCode language) Get a list ofLocaleCode
instances whose language matches the given one.static List<LocaleCode>
getByLanguage
(String language) Get a list ofLocaleCode
instances whose language matches the given one.static List<LocaleCode>
getByLanguage
(String language, boolean caseSensitive) Get a list ofLocaleCode
instances whose language matches the given one.static List<LocaleCode>
getByLanguageIgnoreCase
(String language) Get a list ofLocaleCode
instances whose language matches the given one.static LocaleCode
getByLocale
(Locale locale) Get aLocaleCode
instance that corresponds to the givenLocale
instance.Get the country code.Get the language code.toLocale()
Convert thisLocaleCode
instance to aLocale
instance.toString()
Get the string representation of this locale code.static LocaleCode
Returns the enum constant of this class with the specified name.static LocaleCode[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
undefined
- Since:
- 1.14
-
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
- Since:
- 1.22
-
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
- Since:
- 1.21
-
fa_IR
- Since:
- 1.21
-
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
- Since:
- 1.22
-
ko
-
ko_KR
-
lt
-
lt_LT
-
lv
-
lv_LV
-
mk
-
mk_MK
-
ms
-
ms_MY
-
mt
-
mt_MT
-
nb
- Since:
- 1.8
-
nb_NO
- Since:
- 1.8
-
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
- Since:
- 1.22
-
ru_RU
-
se
- Since:
- 1.8
-
se_NO
- Since:
- 1.8
-
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
-
vi
-
vi_VN
-
zh
-
zh_CN
-
zh_HK
-
zh_SG
-
zh_TW
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getByCode
Get aLocaleCode
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 ofgetByCode(code, false)
.- Parameters:
code
- A locale code.- Returns:
- A
LocaleCode
instance, ornull
if not found. - See Also:
-
getByCodeIgnoreCase
Get aLocaleCode
instance that corresponds to the given code.This method just calls
getByCode
(code, false)
.- Parameters:
code
- A locale code.- Returns:
- A
LocaleCode
instance, ornull
if not found. - Since:
- 1.13
- See Also:
-
getByCode
Get aLocaleCode
instance that corresponds to the given code.The format of the code should be either of the following:
- language
- language
-
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.
- Parameters:
code
- A locale code.caseSensitive
- Iftrue
, the language part of the given code must be lower-case and the country part, if notnull
, must be upper-case. If false, this method internally canonicalizes the given code and then performs search.- Returns:
- A
LocaleCode
instance, ornull
if not found.
-
getByCode
Get aLocaleCode
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 ofgetByCode(language, country, false)
.- Parameters:
language
- <a href="href="http://en.wikipedia.org/wiki/ISO_639-1" >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).- Returns:
- A
LocaleCode
, ornull
if not found. - See Also:
-
getByCodeIgnoreCase
Get aLocaleCode
instance that corresponds to the given pair of language code and country code.This method just calls
getByCode
(language, country, false)
.- Parameters:
language
- <a href="href="http://en.wikipedia.org/wiki/ISO_639-1" >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).- Returns:
- A
LocaleCode
, ornull
if not found. - Since:
- 1.13
- See Also:
-
getByCode
Get aLocaleCode
instance that corresponds to the given pair of language code and country code.If
language
is "undefined" and ifcountry
isnull
or "UNDEFINED",LocaleCode.undefined
is returned.- Parameters:
language
- <a href="href="http://en.wikipedia.org/wiki/ISO_639-1" >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
- Iftrue
, the given language code must be lower-case and the given country code, if notnull
, must be upper-case. Iffalse
, this method internally canonicalizes the given codes and then performs search.- Returns:
- A
LocaleCode
, ornull
if not found.
-
getByLocale
Get aLocaleCode
instance that corresponds to the givenLocale
instance.- Parameters:
locale
- ALocale
instance.- Returns:
- A
LocaleCode
instance, ornull
if not found. When the value returned bygetLanguage()
method of the given instance isnull
or an empty string and the value returned bygetCountry()
method of the given instance isnull
or an empty string,LocaleCode.undefined
is returned.
-
getByLanguage
Get a list ofLocaleCode
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 ofgetByLanguage(language, false)
.- Parameters:
language
- Language code. ISO 639 alpha-2 or alpha-3.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose language matches the given one, the size of the returned list is zero. - Since:
- 1.3
-
getByLanguageIgnoreCase
Get a list ofLocaleCode
instances whose language matches the given one.This method is an alias of
getByLanguage
(language, false)
.- Parameters:
language
- Language code. ISO 639 alpha-2 or alpha-3.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose language matches the given one, the size of the returned list is zero. - Since:
- 1.13
-
getByLanguage
Get a list ofLocaleCode
instances whose language matches the given one.This method is an alias of
getByLanguage
(
LanguageCode
.
getByCode
(language, caseSensitive))
.- Parameters:
language
- Language code. ISO 639 alpha-2 or alpha-3.caseSensitive
- Iftrue
, the given code should consist of lowercase letters only. Iffalse
, case is ignored.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose language matches the given one, the size of the returned list is zero. - Since:
- 1.3
-
getByLanguage
Get a list ofLocaleCode
instances whose language matches the given one.- Parameters:
language
-LanguageCode
instance that represents a language.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose language matches the given one, the size of the returned list is zero. - Since:
- 1.3
-
getByCountry
Get a list ofLocaleCode
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 ofgetByCountry(country, false)
.- Parameters:
country
- Country code. ISO 3166-1 alpha-2 or alpha-3.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose country matches the given one, the size of the returned list is zero. - Since:
- 1.3
-
getByCountryIgnoreCase
Get a list ofLocaleCode
instances whose country matches the given one.This method is an alias of
getByCountry
(country, false)
.- Parameters:
country
- Country code. ISO 3166-1 alpha-2 or alpha-3.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose country matches the given one, the size of the returned list is zero. - Since:
- 1.13
-
getByCountry
Get a list ofLocaleCode
instances whose country matches the given one.This method is an alias of
getByCountry
(
CountryCode
.
getByCode
(country, caseSensitive))
.- Parameters:
country
- Country code. ISO 3166-1 alpha-2 or alpha-3.caseSensitive
- Iftrue
, the given code should consist of uppercase letters only. Iffalse
, case is ignored.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose country matches the given one, the size of the returned list is zero. - Since:
- 1.3
-
getByCountry
Get a list ofLocaleCode
instances whose country matches the given one.- Parameters:
country
-CountryCode
instance that represents a country.- Returns:
- List of
LocaleCode
instances. If there is noLocaleCode
instance whose country matches the given one, the size of the returned list is zero. - Since:
- 1.3
-
getLanguage
Get the language code.- Returns:
- The language code. This method always returns a non-null value.
-
getCountry
Get the country code.- Returns:
- The country code. This method may return null.
For example,
LocaleCode.en
.getCountry() returns null.
-
toString
Get the string representation of this locale code. Its format is either of the following:- language
- language
-
country
where language is an ISO 639-1 code and country is an ISO 3166-1 alpha-2 code.
- Overrides:
toString
in classEnum<LocaleCode>
- Returns:
- The string representation of this locale code.
-
toLocale
Convert thisLocaleCode
instance to aLocale
instance.In most cases, this method creates a new
Locale
instance every time it is called, but someLocaleCode
instances return their corresponding entries inLocale
class. For example,LocaleCode.it
always returnsLocale.ITALIAN
.The table below lists
LocaleCode
entries whosetoLocale()
does not create a newLocale
instance but returns an entry inLocale
class.In addition,
toLocale()
ofLocaleCode.undefined
behaves a bit differently. It returnsLocale.ROOT
when it is available (i.e. when the version of Java SE is 1.6 or higher). Otherwise, it returns aLocale
instance whose language and country are empty strings. Even in the latter case, the same instance is returned on every call.- Returns:
- A
Locale
instance that matches thisLocaleCode
.
-
nb
ornb_NO
should be used.