Enum LanguageCode
- java.lang.Object
-
- java.lang.Enum<LanguageCode>
-
- com.neovisionaries.i18n.LanguageCode
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<LanguageCode>
public enum LanguageCode extends java.lang.Enum<LanguageCode>
ISO 639-1 language code.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");
-
-
Enum Constant Summary
Enum Constants Enum Constant Description 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
undefined
Undefined.ur
uz
ve
vi
Vietnamese (vie
).vo
wa
wo
xh
yi
yo
za
zh
zu
-
Constructor Summary
Constructors Modifier Constructor Description private
LanguageCode()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.String
canonicalize(java.lang.String code, boolean caseSensitive)
Canonicalize the given language code.static java.util.List<LanguageCode>
findByName(java.lang.String regex)
Get a list ofLanguageCode
by a name regular expression.static java.util.List<LanguageCode>
findByName(java.util.regex.Pattern pattern)
Get a list ofLanguageCode
by a name pattern.LanguageAlpha3Code
getAlpha3()
Get ISO 639-2 language code (3-letter lowercase code(s)).static LanguageCode
getByCode(java.lang.String code)
static LanguageCode
getByCode(java.lang.String code, boolean caseSensitive)
static LanguageCode
getByCodeIgnoreCase(java.lang.String code)
(package private) static LanguageCode
getByEnumName(java.lang.String name)
static LanguageCode
getByLocale(java.util.Locale locale)
Get aLanguageCode
that corresponds to the language code of the givenLocale
instance.java.lang.String
getName()
Get the language name.java.util.Locale
toLocale()
Convert thisLanguageCode
instance to aLocale
instance.static LanguageCode
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static LanguageCode[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
undefined
public static final LanguageCode undefined
Undefined.This is not an official ISO 639-1 code.
- Since:
- 1.14
-
aa
public static final LanguageCode aa
-
ab
public static final LanguageCode ab
-
ae
public static final LanguageCode ae
-
af
public static final LanguageCode af
-
ak
public static final LanguageCode ak
-
am
public static final LanguageCode am
-
an
public static final LanguageCode an
-
ar
public static final LanguageCode ar
-
as
public static final LanguageCode as
-
av
public static final LanguageCode av
-
ay
public static final LanguageCode ay
-
az
public static final LanguageCode az
Azerbaijani (aze
).
-
ba
public static final LanguageCode ba
-
be
public static final LanguageCode be
Belarusian (bel
).
-
bg
public static final LanguageCode bg
-
bh
public static final LanguageCode bh
-
bi
public static final LanguageCode bi
-
bm
public static final LanguageCode bm
-
bn
public static final LanguageCode bn
-
bo
public static final LanguageCode bo
-
br
public static final LanguageCode br
-
bs
public static final LanguageCode bs
-
ca
public static final LanguageCode ca
-
ce
public static final LanguageCode ce
-
ch
public static final LanguageCode ch
-
co
public static final LanguageCode co
-
cr
public static final LanguageCode cr
-
cs
public static final LanguageCode cs
-
cu
public static final LanguageCode cu
-
cv
public static final LanguageCode cv
-
cy
public static final LanguageCode cy
-
da
public static final LanguageCode da
-
de
public static final LanguageCode de
-
dv
public static final LanguageCode dv
-
dz
public static final LanguageCode dz
-
ee
public static final LanguageCode ee
-
el
public static final LanguageCode el
-
en
public static final LanguageCode en
-
eo
public static final LanguageCode eo
-
es
public static final LanguageCode es
-
et
public static final LanguageCode et
-
eu
public static final LanguageCode eu
-
fa
public static final LanguageCode fa
-
ff
public static final LanguageCode ff
-
fi
public static final LanguageCode fi
-
fj
public static final LanguageCode fj
-
fo
public static final LanguageCode fo
-
fr
public static final LanguageCode fr
-
fy
public static final LanguageCode fy
West Frisian (fry
).
-
ga
public static final LanguageCode ga
-
gd
public static final LanguageCode gd
-
gl
public static final LanguageCode gl
-
gn
public static final LanguageCode gn
-
gu
public static final LanguageCode gu
-
gv
public static final LanguageCode gv
-
ha
public static final LanguageCode ha
-
he
public static final LanguageCode he
-
hi
public static final LanguageCode hi
-
ho
public static final LanguageCode ho
-
hr
public static final LanguageCode hr
-
ht
public static final LanguageCode ht
-
hu
public static final LanguageCode hu
-
hy
public static final LanguageCode hy
-
hz
public static final LanguageCode hz
-
ia
public static final LanguageCode ia
Interlingua (ina
).
-
id
public static final LanguageCode id
Indonesian (ind
).
-
ie
public static final LanguageCode ie
Interlingue (ile
).
-
ig
public static final LanguageCode ig
-
ii
public static final LanguageCode ii
-
ik
public static final LanguageCode ik
-
io
public static final LanguageCode io
-
is
public static final LanguageCode is
-
it
public static final LanguageCode it
-
iu
public static final LanguageCode iu
-
ja
public static final LanguageCode ja
-
jv
public static final LanguageCode jv
-
ka
public static final LanguageCode ka
-
kg
public static final LanguageCode kg
-
ki
public static final LanguageCode ki
-
kj
public static final LanguageCode kj
-
kk
public static final LanguageCode kk
-
kl
public static final LanguageCode kl
Kalaallisut (kal
).
-
km
public static final LanguageCode km
-
kn
public static final LanguageCode kn
-
ko
public static final LanguageCode ko
-
kr
public static final LanguageCode kr
-
ks
public static final LanguageCode ks
-
ku
public static final LanguageCode ku
-
kv
public static final LanguageCode kv
-
kw
public static final LanguageCode kw
-
ky
public static final LanguageCode ky
-
la
public static final LanguageCode la
-
lb
public static final LanguageCode lb
Luxembourgish (ltz
).
-
lg
public static final LanguageCode lg
-
li
public static final LanguageCode li
Limburgish (lim
).
-
ln
public static final LanguageCode ln
-
lo
public static final LanguageCode lo
-
lt
public static final LanguageCode lt
Lithuanian (lit
).
-
lu
public static final LanguageCode lu
Luba-Katanga (lub
).
-
lv
public static final LanguageCode lv
-
mg
public static final LanguageCode mg
-
mh
public static final LanguageCode mh
Marshallese (mah
).
-
mi
public static final LanguageCode mi
-
mk
public static final LanguageCode mk
-
ml
public static final LanguageCode ml
-
mn
public static final LanguageCode mn
-
mr
public static final LanguageCode mr
-
ms
public static final LanguageCode ms
-
mt
public static final LanguageCode mt
-
my
public static final LanguageCode my
-
na
public static final LanguageCode na
-
nb
public static final LanguageCode nb
-
nd
public static final LanguageCode nd
-
ne
public static final LanguageCode ne
-
ng
public static final LanguageCode ng
-
nl
public static final LanguageCode nl
-
nn
public static final LanguageCode nn
-
no
public static final LanguageCode no
Deprecated.nb
should be used.
-
nr
public static final LanguageCode nr
-
nv
public static final LanguageCode nv
-
ny
public static final LanguageCode ny
-
oc
public static final LanguageCode oc
-
oj
public static final LanguageCode oj
-
om
public static final LanguageCode om
-
or
public static final LanguageCode or
-
os
public static final LanguageCode os
-
pa
public static final LanguageCode pa
-
pi
public static final LanguageCode pi
-
pl
public static final LanguageCode pl
-
ps
public static final LanguageCode ps
-
pt
public static final LanguageCode pt
Portuguese (por
).
-
qu
public static final LanguageCode qu
-
rm
public static final LanguageCode rm
-
rn
public static final LanguageCode rn
-
ro
public static final LanguageCode ro
-
ru
public static final LanguageCode ru
-
rw
public static final LanguageCode rw
Kinyarwanda (kin
).
-
sa
public static final LanguageCode sa
-
sc
public static final LanguageCode sc
-
sd
public static final LanguageCode sd
-
se
public static final LanguageCode se
Northern Sami (sme
).
-
sg
public static final LanguageCode sg
-
si
public static final LanguageCode si
-
sk
public static final LanguageCode sk
-
sl
public static final LanguageCode sl
-
sm
public static final LanguageCode sm
-
sn
public static final LanguageCode sn
-
so
public static final LanguageCode so
-
sq
public static final LanguageCode sq
-
sr
public static final LanguageCode sr
-
ss
public static final LanguageCode ss
-
st
public static final LanguageCode st
-
su
public static final LanguageCode su
-
sv
public static final LanguageCode sv
-
sw
public static final LanguageCode sw
-
ta
public static final LanguageCode ta
-
te
public static final LanguageCode te
-
tg
public static final LanguageCode tg
-
th
public static final LanguageCode th
-
ti
public static final LanguageCode ti
-
tk
public static final LanguageCode tk
-
tl
public static final LanguageCode tl
-
tn
public static final LanguageCode tn
-
to
public static final LanguageCode to
-
tr
public static final LanguageCode tr
-
ts
public static final LanguageCode ts
-
tt
public static final LanguageCode tt
-
tw
public static final LanguageCode tw
-
ty
public static final LanguageCode ty
-
ug
public static final LanguageCode ug
-
uk
public static final LanguageCode uk
-
ur
public static final LanguageCode ur
-
uz
public static final LanguageCode uz
-
ve
public static final LanguageCode ve
-
vi
public static final LanguageCode vi
Vietnamese (vie
).
-
vo
public static final LanguageCode vo
-
wa
public static final LanguageCode wa
-
wo
public static final LanguageCode wo
-
xh
public static final LanguageCode xh
-
yi
public static final LanguageCode yi
-
yo
public static final LanguageCode yo
-
za
public static final LanguageCode za
-
zh
public static final LanguageCode zh
-
zu
public static final LanguageCode zu
-
-
Method Detail
-
values
public static LanguageCode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (LanguageCode c : LanguageCode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static LanguageCode valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getName
public java.lang.String getName()
Get the language name.- Returns:
- The language name.
-
toLocale
public java.util.Locale 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.LanguageCode Locale LanguageCode.de
Locale.GERMAN
LanguageCode.en
Locale.ENGLISH
LanguageCode.fr
Locale.FRENCH
LanguageCode.it
Locale.ITALIAN
LanguageCode.ja
Locale.JAPANESE
LanguageCode.ko
Locale.KOREAN
LanguageCode.zh
Locale.CHINESE
- Returns:
- A
Locale
instance that matches thisLanguageCode
.
-
getAlpha3
public LanguageAlpha3Code 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
-
getByCode
public static LanguageCode getByCode(java.lang.String code)
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
public static LanguageCode getByCodeIgnoreCase(java.lang.String code)
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
public static LanguageCode getByCode(java.lang.String code, boolean caseSensitive)
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.
-
getByEnumName
static LanguageCode getByEnumName(java.lang.String name)
-
getByLocale
public static LanguageCode getByLocale(java.util.Locale locale)
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:
Locale.getLanguage()
-
canonicalize
static java.lang.String canonicalize(java.lang.String code, boolean caseSensitive)
Canonicalize the given language code.- If the given code is
null
or an empty string,null
is returned. - Otherwise, if the given code matches one of three legacy
language code ("iw", "ji" and "in"), its official counterpart
("he", "yi" and "id", respectively) is returned. Note that
String.equals(Object)
is used for comparison ifcaseSensitive
istrue
and thatString.equalsIgnoreCase(String)
is used ifcaseSensitive
isfalse
. - Otherwise, if
caseSensitive
istrue
, the given code is returned as is. - Otherwise,
code.toLowercase()
is returned.
- Parameters:
code
- ISO 639-1 code.caseSensitive
-true
if the code should be handled case-sensitively.- Returns:
- Canonicalized language code.
- If the given code is
-
findByName
public static java.util.List<LanguageCode> findByName(java.lang.String regex)
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:
java.lang.IllegalArgumentException
-regex
isnull
.java.util.regex.PatternSyntaxException
-regex
failed to be compiled.- Since:
- 1.11
-
findByName
public static java.util.List<LanguageCode> findByName(java.util.regex.Pattern pattern)
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:
java.lang.IllegalArgumentException
-pattern
isnull
.- Since:
- 1.11
-
-