Enum Class LanguageCode
- All Implemented Interfaces:
Serializable
,Comparable<LanguageCode>
,java.lang.constant.Constable
Enum names of this enum themselves are represented by ISO 639-1 code (2-letter lower-case alphabets).
// List all the language codes. for (LanguageCode code : LanguageCode.values()) { // For example, "[ar] Arabic" is printed. System.out.format("[%s] %s\n", code, code.getName()
); } // Get a LanguageCode instance by ISO 639-1 code. LanguageCode code = LanguageCode.getByCode
("fr"); // Convert to a Locale instance. Locale locale = code.toLocale()
; // Get a LanguageCode by a Locale instance. code = LanguageCode.getByLocale
(locale); // Get a list by a regular expression for names. // // The list will contain: // // LanguageCode.an : Aragonese // LanguageCode.ja : Japanese // LanguageCode.jv : Javanese // LanguageCode.su : Sundanese // LanguageCode.zh : Chinese // List<LanguageCode> list = LanguageCode.findByName
(".*nese");
- Author:
- Takahiko Kawasaki
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionAzerbaijani (aze
).Belarusian (bel
).West Frisian (fry
).Interlingua (ina
).Indonesian (ind
).Interlingue (ile
).Kalaallisut (kal
).Luxembourgish (ltz
).Limburgish (lim
).Lithuanian (lit
).Luba-Katanga (lub
).Marshallese (mah
).Deprecated.Portuguese (por
).Kinyarwanda (kin
).Northern Sami (sme
).Undefined.Vietnamese (vie
). -
Method Summary
Modifier and TypeMethodDescriptionstatic List<LanguageCode>
findByName
(String regex) Get a list ofLanguageCode
by a name regular expression.static List<LanguageCode>
findByName
(Pattern pattern) Get a list ofLanguageCode
by a name pattern.Get ISO 639-2 language code (3-letter lowercase code(s)).static LanguageCode
static LanguageCode
static LanguageCode
getByCodeIgnoreCase
(String code) static LanguageCode
getByLocale
(Locale locale) Get aLanguageCode
that corresponds to the language code of the givenLocale
instance.getName()
Get the language name.toLocale()
Convert thisLanguageCode
instance to aLocale
instance.static LanguageCode
Returns the enum constant of this class with the specified name.static LanguageCode[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
undefined
Undefined.This is not an official ISO 639-1 code.
- Since:
- 1.14
-
aa
-
ab
-
ae
-
af
-
ak
-
am
-
an
-
ar
-
as
-
av
-
ay
-
az
Azerbaijani (aze
). -
ba
-
be
Belarusian (bel
). -
bg
-
bh
-
bi
-
bm
-
bn
-
bo
-
br
-
bs
-
ca
-
ce
-
ch
-
co
-
cr
-
cs
-
cu
-
cv
-
cy
-
da
-
de
-
dv
-
dz
-
ee
-
el
-
en
-
eo
-
es
-
et
-
eu
-
fa
-
ff
-
fi
-
fj
-
fo
-
fr
-
fy
West Frisian (fry
). -
ga
-
gd
-
gl
-
gn
-
gu
-
gv
-
ha
-
he
-
hi
-
ho
-
hr
-
ht
-
hu
-
hy
-
hz
-
ia
Interlingua (ina
). -
id
Indonesian (ind
). -
ie
Interlingue (ile
). -
ig
-
ii
-
ik
-
io
-
is
-
it
-
iu
-
ja
-
jv
-
ka
-
kg
-
ki
-
kj
-
kk
-
kl
Kalaallisut (kal
). -
km
-
kn
-
ko
-
kr
-
ks
-
ku
-
kv
-
kw
-
ky
-
la
-
lb
Luxembourgish (ltz
). -
lg
-
li
Limburgish (lim
). -
ln
-
lo
-
lt
Lithuanian (lit
). -
lu
Luba-Katanga (lub
). -
lv
-
mg
-
mh
Marshallese (mah
). -
mi
-
mk
-
ml
-
mn
-
mr
-
ms
-
mt
-
my
-
na
-
nb
-
nd
-
ne
-
ng
-
nl
-
nn
-
no
Deprecated.nb
should be used. -
nr
-
nv
-
ny
-
oc
-
oj
-
om
-
or
-
os
-
pa
-
pi
-
pl
-
ps
-
pt
Portuguese (por
). -
qu
-
rm
-
rn
-
ro
-
ru
-
rw
Kinyarwanda (kin
). -
sa
-
sc
-
sd
-
se
Northern Sami (sme
). -
sg
-
si
-
sk
-
sl
-
sm
-
sn
-
so
-
sq
-
sr
-
ss
-
st
-
su
-
sv
-
sw
-
ta
-
te
-
tg
-
th
-
ti
-
tk
-
tl
-
tn
-
to
-
tr
-
ts
-
tt
-
tw
-
ty
-
ug
-
uk
-
ur
-
uz
-
ve
-
vi
Vietnamese (vie
). -
vo
-
wa
-
wo
-
xh
-
yi
-
yo
-
za
-
zh
-
zu
-
-
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 aLanguageCode
that corresponds to a given ISO 639-1 code (2-letter lowercase code) or ISO 639-2 code (3-letter lowercase code).This method 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
- An ISO 639-1 code (2-letter lowercase code) or an ISO 639-2 code (3-letter lowercase code). Or "undefined" (case sensitive). Note that if the given code is one of legacy language codes ("iw", "ji" and "in"), it is treated as its official counterpart ("he", "yi" and "id", respectively). For example, if "in" is given, this method returnsLanguageCode.id
.- Returns:
- A
LanguageCode
instance, ornull
if not found.
-
getByCodeIgnoreCase
Get aLanguageCode
that corresponds to a given ISO 639-1 code (2-letter lowercase code) or ISO 639-2 code (3-letter lowercase code).This method calls
getByCode
(code, false)
.- Parameters:
code
- An ISO 639-1 code (2-letter lowercase code) or an ISO 639-2 code (3-letter lowercase code). Or "undefined" (case insensitive). Note that if the given code is one of legacy language codes ("iw", "ji" and "in"), it is treated as its official counterpart ("he", "yi" and "id", respectively). For example, if "in" is given, this method returnsLanguageCode.id
.- Returns:
- A
LanguageCode
instance, ornull
if not found. - Since:
- 1.13
-
getByCode
Get aLanguageCode
that corresponds to a given ISO 639-1 code (2-letter lowercase code) or ISO 639-2 code (3-letter lowercase code).- Parameters:
code
- An ISO 639-1 code (2-letter lowercase code) or an ISO 639-2 code (3-letter lowercase code). Or "undefined" (its case sensitivity depends on the value ofcaseSensitive
). Note that if the given code is one of legacy language codes ("iw", "ji" and "in"), it is treated as its official counterpart ("he", "yi" and "id", respectively). For example, if "in" is given, this method returnsLanguageCode.id
.caseSensitive
- Iftrue
, the given code should consist of lowercase letters only. Iffalse
, this method internally canonicalizes the given code byString.toLowerCase()
and then performs search. For example,getByCode("JA", true)
returnsnull
, but on the other hand,getByCode("JA", false)
returnsLanguageCode.ja
.- Returns:
- A
LanguageCode
instance, ornull
if not found.
-
getByLocale
Get aLanguageCode
that corresponds to the language code of the givenLocale
instance.- Parameters:
locale
- ALocale
instance.- Returns:
- A
LanguageCode
instance, ornull
if not found. WhengetLanguage()
method of the givenLocale
instance returnsnull
or an empty string,LanguageCode.undefined
is returned. - See Also:
-
findByName
Get a list ofLanguageCode
by a name regular expression.This method is almost equivalent to
findByName
(Pattern.compile(regex))
.- Parameters:
regex
- Regular expression for names.- Returns:
- List of
LanguageCode
. If nothing has matched, an empty list is returned. - Throws:
IllegalArgumentException
-regex
isnull
.PatternSyntaxException
-regex
failed to be compiled.- Since:
- 1.11
-
findByName
Get a list ofLanguageCode
by a name pattern.For example, the list obtained by the code snippet below:
Pattern pattern = Pattern.compile(".*nese"); List<LanguageCode> list = LanguageCode.findByName(pattern);
contains 5
LanguageCode
s as listed below.- Parameters:
pattern
- Pattern to match names.- Returns:
- List of
LanguageCode
. If nothing has matched, an empty list is returned. - Throws:
IllegalArgumentException
-pattern
isnull
.- Since:
- 1.11
-
getName
Get the language name.- Returns:
- The language name.
-
toLocale
Convert thisLanguageCode
instance to aLocale
instance.In most cases, this method creates a new
Locale
instance every time it is called, but someLanguageCode
instances return their corresponding entries inLocale
class. For example,LanguageCode.ja
always returnsLocale.JAPANESE
.The table below lists
LanguageCode
entries whosetoLocale()
do not create newLocale
instances but return entries inLocale
class.- Returns:
- A
Locale
instance that matches thisLanguageCode
.
-
getAlpha3
Get ISO 639-2 language code (3-letter lowercase code(s)).Most languages have just one corresponding ISO 639-2 code, but some languages have two ISO 639-2 codes. They are known as "bibliographic" code (ISO 639-2/B code) and "terminological" code (ISO 639-2/T code). This method returns ISO 639-2/T code. If you want to get ISO 639-2/B code, write like below.
LanguageCode alpha2 = ...;
LanguageAlpha3Code
alpha3B = alpha2.getAlpha3()
.getAlpha3B()
;The above code does no harm for most
LanguageCode
s that have just one ISO 639-2 code.getAlpha3B()
of suchLanguageAlpha3Code
instances just return themselves (=this
object).The table below lists languages having two ISO 639-2 codes.
ISO 639-1 ISO 639-2/T ISO 639-2/B Language bo
bod
tib
Tibetan eu
eus
baq
Basque cs
ces
cze
Czech cy
cym
wel
Welsh de
deu
ger
German el
ell
gre
Greek fa
fas
per
Persian fr
fra
fre
French hy
hye
arm
Armenian is
isl
ice
Icelandic ka
kat
geo
Georgian mi
mri
mao
Māori mk
mkd
mac
Macedonian ms
msa
may
Malay my
mya
bur
Burmese nl
nld
dut
Dutch ro
ron
rum
Romanian sk
slk
slo
Slovak sq
sqi
alb
Albanian - Returns:
- ISO 639-2 language code.
- Since:
- 1.1
-
nb
should be used.