All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neovisionaries.i18n.LanguageCode Maven / Gradle / Ivy

/*
 * Copyright (C) 2012-2014 Neo Visionaries Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.neovisionaries.i18n;


import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;


/**
 * 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.{@link #getName()});
 * }
 *
 * // Get a LanguageCode instance by ISO 639-1 code.
 * LanguageCode code = LanguageCode.{@link #getByCode(String) getByCode}("fr");
 *
 * // Convert to a Locale instance.
 * Locale locale = code.{@link #toLocale()};
 *
 * // Get a LanguageCode by a Locale instance.
 * code = LanguageCode.{@link #getByLocale(Locale) 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.{@link #findByName(String) findByName}(".*nese");
 * 
* * @author Takahiko Kawasaki */ public enum LanguageCode { /** * Undefined. * *

* This is not an official ISO 639-1 code. *

* * @since 1.14 */ undefined() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.undefined; } }, /** * Afar * ({@link LanguageAlpha3Code#aar aar}). */ aa() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.aar; } }, /** * Abkhaz * ({@link LanguageAlpha3Code#abk abk}). */ ab() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.abk; } }, /** * Avestan * ({@link LanguageAlpha3Code#ave ave}). */ ae() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ave; } }, /** * Afrikaans * ({@link LanguageAlpha3Code#afr afr}). */ af() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.afr; } }, /** * Akan * ({@link LanguageAlpha3Code#aka aka}). */ ak() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.aka; } }, /** * Amharic * ({@link LanguageAlpha3Code#amh amh}). */ am() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.amh; } }, /** * Aragonese * ({@link LanguageAlpha3Code#arg arg}). */ an() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.arg; } }, /** * Arabic * ({@link LanguageAlpha3Code#ara ara}). */ ar() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ara; } }, /** * Assamese * ({@link LanguageAlpha3Code#asm asm}). */ as() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.asm; } }, /** * Avaric * ({@link LanguageAlpha3Code#ava ava}). */ av() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ava; } }, /** * Aymara * ({@link LanguageAlpha3Code#aym aym}). */ ay() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.aym; } }, /** * Azerbaijani * ({@link LanguageAlpha3Code#aze aze}). */ az() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.aze; } }, /** * Bashkir * ({@link LanguageAlpha3Code#bak bak}). */ ba() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bak; } }, /** * Belarusian * ({@link LanguageAlpha3Code#bel bel}). */ be() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bel; } }, /** * Bulgarian * ({@link LanguageAlpha3Code#bul bul}). */ bg() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bul; } }, /** * Bihari * ({@link LanguageAlpha3Code#bih bih}). */ bh() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bih; } }, /** * Bislama * ({@link LanguageAlpha3Code#bis bis}). */ bi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bis; } }, /** * Bambara * ({@link LanguageAlpha3Code#bam bam}). */ bm() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bam; } }, /** * Bengali * ({@link LanguageAlpha3Code#ben ben}). */ bn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ben; } }, /** * Tibetan * ({@link LanguageAlpha3Code#bod bod}, {@link LanguageAlpha3Code#tib tib}). */ bo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bod; } }, /** * Breton * ({@link LanguageAlpha3Code#bre bre}). */ br() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bre; } }, /** * Bosnian * ({@link LanguageAlpha3Code#bos bos}). */ bs() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.bos; } }, /** * Catalan * ({@link LanguageAlpha3Code#cat cat}). */ ca() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.cat; } }, /** * Chechen * ({@link LanguageAlpha3Code#che che}). */ ce() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.che; } }, /** * Chamorro * ({@link LanguageAlpha3Code#cha cha}). */ ch() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.cha; } }, /** * Corsican * ({@link LanguageAlpha3Code#cos cos}). */ co() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.cos; } }, /** * Cree * ({@link LanguageAlpha3Code#cre cre}). */ cr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.cre; } }, /** * Czech * ({@link LanguageAlpha3Code#ces ces}, {@link LanguageAlpha3Code#cze cze}). */ cs() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ces; } }, /** * Church Slavonic * ({@link LanguageAlpha3Code#chu chu}). */ cu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.chu; } }, /** * Chuvash * ({@link LanguageAlpha3Code#chv chv}). */ cv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.chv; } }, /** * Welsh * ({@link LanguageAlpha3Code#cym cym}, {@link LanguageAlpha3Code#wel wel}). */ cy() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.cym; } }, /** * Danish * ({@link LanguageAlpha3Code#dan dan}). */ da() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.dan; } }, /** * German * ({@link LanguageAlpha3Code#deu deu}, {@link LanguageAlpha3Code#ger ger}). */ de() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.deu; } @Override public Locale toLocale() { return Locale.GERMAN; } }, /** * Dhivehi * ({@link LanguageAlpha3Code#div div}). */ dv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.div; } }, /** * Dzongkha * ({@link LanguageAlpha3Code#dzo dzo}). */ dz() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.dzo; } }, /** * Ewe * ({@link LanguageAlpha3Code#ewe ewe}). */ ee() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ewe; } }, /** * Greek * ({@link LanguageAlpha3Code#ell ell}, {@link LanguageAlpha3Code#gre gre}). */ el() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ell; } }, /** * English * ({@link LanguageAlpha3Code#eng eng}). */ en() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.eng; } @Override public Locale toLocale() { return Locale.ENGLISH; } }, /** * Esperanto * ({@link LanguageAlpha3Code#epo epo}). */ eo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.epo; } }, /** * Spanish * ({@link LanguageAlpha3Code#spa spa}). */ es() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.spa; } }, /** * Estonian * ({@link LanguageAlpha3Code#est est}). */ et() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.est; } }, /** * Basque * ({@link LanguageAlpha3Code#eus eus}, {@link LanguageAlpha3Code#baq baq}). */ eu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.eus; } }, /** * Persian * ({@link LanguageAlpha3Code#fas fas}, {@link LanguageAlpha3Code#per per}). */ fa() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.fas; } }, /** * Fula * ({@link LanguageAlpha3Code#ful ful}). */ ff() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ful; } }, /** * Finnish * ({@link LanguageAlpha3Code#fin fin}). */ fi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.fin; } }, /** * Fijian * ({@link LanguageAlpha3Code#fij fij}). */ fj() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.fij; } }, /** * Faroese * ({@link LanguageAlpha3Code#fao fao}). */ fo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.fao; } }, /** * French * ({@link LanguageAlpha3Code#fra fra}, {@link LanguageAlpha3Code#fre fre}). */ fr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.fra; } @Override public Locale toLocale() { return Locale.FRENCH; } }, /** * West Frisian * ({@link LanguageAlpha3Code#fry fry}). */ fy() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.fry; } }, /** * Irish * ({@link LanguageAlpha3Code#gle gle}). */ ga() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.gle; } }, /** * Scottish Gaelic * ({@link LanguageAlpha3Code#gla gla}). */ gd() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.gla; } }, /** * Galician * ({@link LanguageAlpha3Code#glg glg}). */ gl() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.glg; } }, /** * Guaraní * ({@link LanguageAlpha3Code#grn grn}). */ gn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.grn; } }, /** * Gujarati * ({@link LanguageAlpha3Code#guj guj}). */ gu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.guj; } }, /** * Manx * ({@link LanguageAlpha3Code#glv glv}). */ gv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.glv; } }, /** * Hausa * ({@link LanguageAlpha3Code#hau hau}). */ ha() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hau; } }, /** * Hebrew * ({@link LanguageAlpha3Code#heb heb}). */ he() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.heb; } }, /** * Hindi * ({@link LanguageAlpha3Code#hin hin}). */ hi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hin; } }, /** * Hiri Motu * ({@link LanguageAlpha3Code#hmo hmo}). */ ho() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hmo; } }, /** * Croatian * ({@link LanguageAlpha3Code#hrv hrv}). */ hr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hrv; } }, /** * Haitian * ({@link LanguageAlpha3Code#hat hat}). */ ht() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hat; } }, /** * Hungarian * ({@link LanguageAlpha3Code#hun hun}). */ hu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hun; } }, /** * Armenian * ({@link LanguageAlpha3Code#hye hye}, {@link LanguageAlpha3Code#arm arm}). */ hy() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.hye; } }, /** * Herero * ({@link LanguageAlpha3Code#her her}). */ hz() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.her; } }, /** * Interlingua * ({@link LanguageAlpha3Code#ina ina}). */ ia() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ina; } }, /** * Indonesian * ({@link LanguageAlpha3Code#ind ind}). */ id() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ind; } }, /** * Interlingue * ({@link LanguageAlpha3Code#ile ile}). */ ie() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ile; } }, /** * Igbo * ({@link LanguageAlpha3Code#ibo ibo}). */ ig() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ibo; } }, /** * Nuosu * ({@link LanguageAlpha3Code#iii iii}). */ ii() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.iii; } }, /** * Inupiaq * ({@link LanguageAlpha3Code#ipk ipk}). */ ik() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ipk; } }, /** * Ido * ({@link LanguageAlpha3Code#ido ido}). */ io() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ido; } }, /** * Icelandic * ({@link LanguageAlpha3Code#isl isl}, {@link LanguageAlpha3Code#ice ice}). */ is() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.isl; } }, /** * Italian * ({@link LanguageAlpha3Code#ita ita}). */ it() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ita; } @Override public Locale toLocale() { return Locale.ITALIAN; } }, /** * Inuktitut * ({@link LanguageAlpha3Code#iku iku}). */ iu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.iku; } }, /** * Japanese * ({@link LanguageAlpha3Code#jpn jpn}). */ ja() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.jpn; } @Override public Locale toLocale() { return Locale.JAPANESE; } }, /** * Javanese * ({@link LanguageAlpha3Code#jav jav}). */ jv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.jav; } }, /** * Georgian * ({@link LanguageAlpha3Code#kat kat}, {@link LanguageAlpha3Code#geo geo}). */ ka() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kat; } }, /** * Kongo * ({@link LanguageAlpha3Code#kon kon}). */ kg() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kon; } }, /** * Kikuyu * ({@link LanguageAlpha3Code#kik kik}). */ ki() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kik; } }, /** * Kwanyama * ({@link LanguageAlpha3Code#kua kua}). */ kj() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kua; } }, /** * Kazakh * ({@link LanguageAlpha3Code#kaz kaz}). */ kk() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kaz; } }, /** * Kalaallisut * ({@link LanguageAlpha3Code#kal kal}). */ kl() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kal; } }, /** * Khmer * ({@link LanguageAlpha3Code#khm khm}). */ km() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.khm; } }, /** * Kannada * ({@link LanguageAlpha3Code#kan kan}). */ kn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kan; } }, /** * Korean * ({@link LanguageAlpha3Code#kor kor}). */ ko() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kor; } @Override public Locale toLocale() { return Locale.KOREAN; } }, /** * Kanuri * ({@link LanguageAlpha3Code#kau kau}). */ kr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kau; } }, /** * Kashmiri * ({@link LanguageAlpha3Code#kas kas}). */ ks() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kas; } }, /** * Kurdish * ({@link LanguageAlpha3Code#kur kur}). */ ku() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kur; } }, /** * Komi * ({@link LanguageAlpha3Code#kom kom}). */ kv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kom; } }, /** * Cornish * ({@link LanguageAlpha3Code#cor cor}). */ kw() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.cor; } }, /** * Kyrgyz * ({@link LanguageAlpha3Code#kir kir}). */ ky() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kir; } }, /** * Latin * ({@link LanguageAlpha3Code#lat lat}). */ la() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lat; } }, /** * Luxembourgish * ({@link LanguageAlpha3Code#ltz ltz}). */ lb() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ltz; } }, /** * Ganda * ({@link LanguageAlpha3Code#lug lug}). */ lg() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lug; } }, /** * Limburgish * ({@link LanguageAlpha3Code#lim lim}). */ li() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lim; } }, /** * Lingala * ({@link LanguageAlpha3Code#lin lin}). */ ln() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lin; } }, /** * Lao * ({@link LanguageAlpha3Code#lao lao}). */ lo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lao; } }, /** * Lithuanian * ({@link LanguageAlpha3Code#lit lit}). */ lt() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lit; } }, /** * Luba-Katanga * ({@link LanguageAlpha3Code#lub lub}). */ lu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lub; } }, /** * Latvian * ({@link LanguageAlpha3Code#lav lav}). */ lv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.lav; } }, /** * Malagasy * ({@link LanguageAlpha3Code#mlg mlg}). */ mg() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mlg; } }, /** * Marshallese * ({@link LanguageAlpha3Code#mah mah}). */ mh() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mah; } }, /** * Māori * ({@link LanguageAlpha3Code#mri mir}, {@link LanguageAlpha3Code#mao mao}). */ mi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mri; } }, /** * Macedonian * ({@link LanguageAlpha3Code#mkd mkd}, {@link LanguageAlpha3Code#mac mac})). */ mk() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mkd; } }, /** * Malayalam * ({@link LanguageAlpha3Code#mal mal}). */ ml() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mal; } }, /** * Mongolian * ({@link LanguageAlpha3Code#mon mon}). */ mn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mon; } }, /** * Marathi * ({@link LanguageAlpha3Code#mar mar}). */ mr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mar; } }, /** * Malay * ({@link LanguageAlpha3Code#msa msa}, {@link LanguageAlpha3Code#may may}). */ ms() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.msa; } }, /** * Maltese * ({@link LanguageAlpha3Code#mlt mlt}). */ mt() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mlt; } }, /** * Burmese * ({@link LanguageAlpha3Code#mya may}, {@link LanguageAlpha3Code#bur bur}). */ my() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.mya; } }, /** * Nauru * ({@link LanguageAlpha3Code#nau nau}). */ na() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nau; } }, /** * Norwegian Bokmål * ({@link LanguageAlpha3Code#nob nob}). */ nb() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nob; } }, /** * Northern Ndebele * ({@link LanguageAlpha3Code#nde nde}). */ nd() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nde; } }, /** * Nepali * ({@link LanguageAlpha3Code#nep nep}). */ ne() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nep; } }, /** * Ndonga * ({@link LanguageAlpha3Code#ndo ndo}). */ ng() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ndo; } }, /** * Dutch * ({@link LanguageAlpha3Code#nld nld}, {@link LanguageAlpha3Code#dut dut}). */ nl() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nld; } }, /** * Norwegian Nynorsk * ({@link LanguageAlpha3Code#nno nno}). */ nn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nno; } }, /** * Norwegian * ({@link LanguageAlpha3Code#nor nor}). * * @deprecated {@link #nb} should be used. * @see Språkkoder for POSIX locale i Norge * @see Red Hat Bugzilla – Bug 532487 Legacy Norwegian locale (no_NO) * should be removed from language selection menu */ no() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nor; } }, /** * Southern Ndebele * ({@link LanguageAlpha3Code#nbl nbl}). */ nr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nbl; } }, /** * Navajo * ({@link LanguageAlpha3Code#nav nav}). */ nv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nav; } }, /** * Chichewa * ({@link LanguageAlpha3Code#nya nya}). */ ny() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.nya; } }, /** * Occitan * ({@link LanguageAlpha3Code#oci oci}). */ oc() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.oci; } }, /** * Ojibwe * ({@link LanguageAlpha3Code#oji oji}). */ oj() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.oji; } }, /** * Oromo * ({@link LanguageAlpha3Code#orm orm}). */ om() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.orm; } }, /** * Oriya * ({@link LanguageAlpha3Code#ori ori}). */ or() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ori; } }, /** * Ossetian * ({@link LanguageAlpha3Code#oss oss}). */ os() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.oss; } }, /** * Punjabi * ({@link LanguageAlpha3Code#pan pan}). */ pa() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.pan; } }, /** * Pāli * ({@link LanguageAlpha3Code#pli pli}). */ pi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.pli; } }, /** * Polish * ({@link LanguageAlpha3Code#pol pol}). */ pl() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.pol; } }, /** * Pashto * ({@link LanguageAlpha3Code#pus pus}). */ ps() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.pus; } }, /** * Portuguese * ({@link LanguageAlpha3Code#por por}). */ pt() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.por; } }, /** * Quechua * ({@link LanguageAlpha3Code#que que}). */ qu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.que; } }, /** * Romansh * ({@link LanguageAlpha3Code#roh roh}). */ rm() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.roh; } }, /** * Kirundi * ({@link LanguageAlpha3Code#run run}). */ rn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.run; } }, /** * Romanian * ({@link LanguageAlpha3Code#ron ron}, {@link LanguageAlpha3Code#rum rum}). */ ro() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ron; } }, /** * Russian * ({@link LanguageAlpha3Code#run run}). */ ru() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.rus; } }, /** * Kinyarwanda * ({@link LanguageAlpha3Code#kin kin}). */ rw() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.kin; } }, /** * Sanskrit * ({@link LanguageAlpha3Code#san san}). */ sa() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.san; } }, /** * Sardinian * ({@link LanguageAlpha3Code#srd srd}). */ sc() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.srd; } }, /** * Sindhi * ({@link LanguageAlpha3Code#snd snd}). */ sd() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.snd; } }, /** * Northern Sami * ({@link LanguageAlpha3Code#sme sme}). */ se() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sme; } }, /** * Sango * ({@link LanguageAlpha3Code#sag sag}). */ sg() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sag; } }, /** * Sinhala * ({@link LanguageAlpha3Code#sin sin}). */ si() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sin; } }, /** * Slovak * ({@link LanguageAlpha3Code#slk slk}, {@link LanguageAlpha3Code#slo slo}). */ sk() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.slk; } }, /** * Slovene * ({@link LanguageAlpha3Code#slv slv}). */ sl() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.slv; } }, /** * Samoan * ({@link LanguageAlpha3Code#smo smo}). */ sm() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.smo; } }, /** * Shona * ({@link LanguageAlpha3Code#sna sna}). */ sn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sna; } }, /** * Somali * ({@link LanguageAlpha3Code#som som}). */ so() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.som; } }, /** * Albanian * ({@link LanguageAlpha3Code#sqi sqi}, {@link LanguageAlpha3Code#alb alb}). */ sq() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sqi; } }, /** * Serbian * ({@link LanguageAlpha3Code#srp srp}). */ sr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.srp; } }, /** * Swati * ({@link LanguageAlpha3Code#ssw ssw}). */ ss() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ssw; } }, /** * Southern Sotho * ({@link LanguageAlpha3Code#sot sot}). */ st() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sot; } }, /** * Sundanese * ({@link LanguageAlpha3Code#sun sun}). */ su() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.sun; } }, /** * Swedish * ({@link LanguageAlpha3Code#swe swe}). */ sv() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.swe; } }, /** * Swahili * ({@link LanguageAlpha3Code#swa swa}). */ sw() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.swa; } }, /** * Tamil * ({@link LanguageAlpha3Code#tam tam}). */ ta() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tam; } }, /** * Telugu * ({@link LanguageAlpha3Code#tel tel}). */ te() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tel; } }, /** * Tajik * ({@link LanguageAlpha3Code#tgk tgk}). */ tg() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tgk; } }, /** * Thai * ({@link LanguageAlpha3Code#tha tha}). */ th() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tha; } }, /** * Tigrinya * ({@link LanguageAlpha3Code#tir tir}). */ ti() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tir; } }, /** * Turkmen * ({@link LanguageAlpha3Code#tuk tuk}). */ tk() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tuk; } }, /** * Tagalog * ({@link LanguageAlpha3Code#tgl tgl}). */ tl() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tgl; } }, /** * Tswana * ({@link LanguageAlpha3Code#tsn tsn}). */ tn() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tsn; } }, /** * Tongan * ({@link LanguageAlpha3Code#ton ton}). */ to() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ton; } }, /** * Turkish * ({@link LanguageAlpha3Code#tur tur}). */ tr() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tur; } }, /** * Tsonga * ({@link LanguageAlpha3Code#tso tso}). */ ts() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tso; } }, /** * Tatar * ({@link LanguageAlpha3Code#tat tat}). */ tt() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tat; } }, /** * Twi * ({@link LanguageAlpha3Code#twi twi}). */ tw() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.twi; } }, /** * Tahitian * ({@link LanguageAlpha3Code#tah tah}). */ ty() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.tah; } }, /** * Uighur * ({@link LanguageAlpha3Code#uig uig}). */ ug() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.uig; } }, /** * Ukrainian * ({@link LanguageAlpha3Code#ukr ukr}). */ uk() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ukr; } }, /** * Urdu * ({@link LanguageAlpha3Code#urd urd}). */ ur() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.urd; } }, /** * Uzbek * ({@link LanguageAlpha3Code#uzb uzb}). */ uz() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.uzb; } }, /** * Venda * ({@link LanguageAlpha3Code#ven ven}). */ ve() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.ven; } }, /** * Vietnamese * ({@link LanguageAlpha3Code#vie vie}). */ vi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.vie; } }, /** * Volapük * ({@link LanguageAlpha3Code#vol vol}). */ vo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.vol; } }, /** * Walloon * ({@link LanguageAlpha3Code#wln wln}). */ wa() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.wln; } }, /** * Wolof * ({@link LanguageAlpha3Code#wol wol}). */ wo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.wol; } }, /** * Xhosa * ({@link LanguageAlpha3Code#xho xho}). */ xh() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.xho; } }, /** * Yiddish * ({@link LanguageAlpha3Code#yid yid}). */ yi() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.yid; } }, /** * Yoruba * ({@link LanguageAlpha3Code#yor yor}). */ yo() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.yor; } }, /** * Zhuang * ({@link LanguageAlpha3Code#zha zha}). */ za() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.zha; } }, /** * Chinese * ({@link LanguageAlpha3Code#zho zho}, {@link LanguageAlpha3Code#chi chi}). */ zh() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.zho; } @Override public Locale toLocale() { return Locale.CHINESE; } }, /** * Zulu * ({@link LanguageAlpha3Code#zul zul}). */ zu() { @Override public LanguageAlpha3Code getAlpha3() { return LanguageAlpha3Code.zul; } } ; private LanguageCode() { } /** * Get the language name. * * @return * The language name. */ public String getName() { return getAlpha3().getName(); } /** * Convert this {@code LanguageCode} instance to a {@link Locale} instance. * *

* In most cases, this method creates a new {@code Locale} instance * every time it is called, but some {@code LanguageCode} instances return * their corresponding entries in {@code Locale} class. For example, * {@link #ja LanguageCode.ja} always returns {@link Locale#JAPANESE}. *

* *

* The table below lists {@code LanguageCode} entries whose {@code toLocale()} * do not create new {@code Locale} instances but return entries in * {@code Locale} class. *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
LanguageCodeLocale
{@link LanguageCode#de LanguageCode.de}{@link Locale#GERMAN}
{@link LanguageCode#en LanguageCode.en}{@link Locale#ENGLISH}
{@link LanguageCode#fr LanguageCode.fr}{@link Locale#FRENCH}
{@link LanguageCode#it LanguageCode.it}{@link Locale#ITALIAN}
{@link LanguageCode#ja LanguageCode.ja}{@link Locale#JAPANESE}
{@link LanguageCode#ko LanguageCode.ko}{@link Locale#KOREAN}
{@link LanguageCode#zh LanguageCode.zh}{@link Locale#CHINESE}
* * @return * A {@code Locale} instance that matches this {@code LanguageCode}. */ public Locale toLocale() { return new Locale(name()); } /** * 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 = ...;
     *
     * {@link LanguageAlpha3Code} alpha3B = alpha2.{@link #getAlpha3()}.{@link
     * LanguageAlpha3Code#getAlpha3B() getAlpha3B()};
     * 
* *

* The above code does no harm for most {@code LanguageCode}s that have * just one ISO 639-2 code. {@link LanguageAlpha3Code#getAlpha3B() * getAlpha3B()} of such {@code LanguageAlpha3Code} instances just return * themselves (= this object). *

* *

* The table below lists languages having two ISO 639-2 codes. *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ISO 639-1ISO 639-2/TISO 639-2/BLanguage
{@link LanguageCode#bo bo}{@link LanguageAlpha3Code#bod bod}{@link LanguageAlpha3Code#tib tib}Tibetan
{@link LanguageCode#eu eu}{@link LanguageAlpha3Code#eus eus}{@link LanguageAlpha3Code#baq baq}Basque
{@link LanguageCode#cs cs}{@link LanguageAlpha3Code#ces ces}{@link LanguageAlpha3Code#cze cze}Czech
{@link LanguageCode#cy cy}{@link LanguageAlpha3Code#cym cym}{@link LanguageAlpha3Code#wel wel}Welsh
{@link LanguageCode#de de}{@link LanguageAlpha3Code#deu deu}{@link LanguageAlpha3Code#ger ger}German
{@link LanguageCode#el el}{@link LanguageAlpha3Code#ell ell}{@link LanguageAlpha3Code#gre gre}Greek
{@link LanguageCode#fa fa}{@link LanguageAlpha3Code#fas fas}{@link LanguageAlpha3Code#per per}Persian
{@link LanguageCode#fr fr}{@link LanguageAlpha3Code#fra fra}{@link LanguageAlpha3Code#fre fre}French
{@link LanguageCode#hy hy}{@link LanguageAlpha3Code#hye hye}{@link LanguageAlpha3Code#arm arm}Armenian
{@link LanguageCode#is is}{@link LanguageAlpha3Code#isl isl}{@link LanguageAlpha3Code#ice ice}Icelandic
{@link LanguageCode#ka ka}{@link LanguageAlpha3Code#kat kat}{@link LanguageAlpha3Code#geo geo}Georgian
{@link LanguageCode#mi mi}{@link LanguageAlpha3Code#mri mri}{@link LanguageAlpha3Code#mao mao}Māori
{@link LanguageCode#mk mk}{@link LanguageAlpha3Code#mkd mkd}{@link LanguageAlpha3Code#mac mac}Macedonian
{@link LanguageCode#ms ms}{@link LanguageAlpha3Code#msa msa}{@link LanguageAlpha3Code#may may}Malay
{@link LanguageCode#my my}{@link LanguageAlpha3Code#mya mya}{@link LanguageAlpha3Code#bur bur}Burmese
{@link LanguageCode#nl nl}{@link LanguageAlpha3Code#nld nld}{@link LanguageAlpha3Code#dut dut}Dutch
{@link LanguageCode#ro ro}{@link LanguageAlpha3Code#ron ron}{@link LanguageAlpha3Code#rum rum}Romanian
{@link LanguageCode#sk sk}{@link LanguageAlpha3Code#slk slk}{@link LanguageAlpha3Code#slo slo}Slovak
{@link LanguageCode#sq sq}{@link LanguageAlpha3Code#sqi sqi}{@link LanguageAlpha3Code#alb alb}Albanian
* * * @return * ISO 639-2 * language code. * * @since 1.1 */ public LanguageAlpha3Code getAlpha3() { return null; } /** * Get a {@code LanguageCode} 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 {@link #getByCode(String, boolean) getByCode}{@code (code, true)}. * Note that the behavior has changed since the version 1.13. In the older versions, * this method was an alias of {@code getByCode(code, false)}. *

* * @param 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 returns {@link #id LanguageCode.id}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. */ public static LanguageCode getByCode(String code) { return getByCode(code, true); } /** * Get a {@code LanguageCode} 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 {@link #getByCode(String, boolean) getByCode}{@code (code, false)}. *

* * @param 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 returns {@link #id LanguageCode.id}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. * * @since 1.13 */ public static LanguageCode getByCodeIgnoreCase(String code) { return getByCode(code, false); } /** * Get a {@code LanguageCode} that corresponds to a given * ISO 639-1 code * (2-letter lowercase code) or * ISO 639-2 code * (3-letter lowercase code). * * @param 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 of {@code caseSensitive}). * 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 returns {@link #id LanguageCode.id}. * * @param caseSensitive * If {@code true}, the given code should consist of lowercase letters only. * If {@code false}, this method internally canonicalizes the given code by * {@link String#toLowerCase()} and then performs search. For example, * {@code getByCode("JA", true)} returns {@code null}, but on the other hand, * {@code getByCode("JA", false)} returns {@link #ja LanguageCode.ja}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. */ public static LanguageCode getByCode(String code, boolean caseSensitive) { code = canonicalize(code, caseSensitive); if (code == null) { return null; } switch (code.length()) { case 2: case 9: return getByEnumName(code); case 3: break; default: return null; } LanguageAlpha3Code alpha3 = LanguageAlpha3Code.getByEnumName(code); if (alpha3 == null) { return null; } // LanguageAlpha3Code.getAlpha2() may return null. return alpha3.getAlpha2(); } static LanguageCode getByEnumName(String name) { try { return Enum.valueOf(LanguageCode.class, name); } catch (IllegalArgumentException e) { return null; } } /** * Get a {@code LanguageCode} that corresponds to the language code of * the given {@link Locale} instance. * * @param locale * A {@code Locale} instance. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. * When {@link Locale#getLanguage() getLanguage()} method of the * given {@code Locale} instance returns {@code null} or an * empty string, {@link #undefined LanguageCode.undefined} is * returned. * * @see Locale#getLanguage() */ public static LanguageCode getByLocale(Locale locale) { if (locale == null) { return null; } // Locale.getLanguage() returns a lowercase ISO 639 code. String language = locale.getLanguage(); if (language == null || language.length() == 0) { return LanguageCode.undefined; } return getByCode(language, true); } /** * Canonicalize the given language code. * *
    *
  1. If the given code is {@code null} or an empty string, * {@code null} is returned. *
  2. 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 * {@code String.equals(Object)} is used for comparison if * {@code caseSensitive} is {@code true} and that * {@code String.equalsIgnoreCase(String)} is used if * {@code caseSensitive} is {@code false}. *
  3. Otherwise, if {@code caseSensitive} is {@code true}, * the given code is returned as is. *
  4. Otherwise, {@code code.toLowercase()} is returned. *
* * @param code * ISO 639-1 code. * * @param caseSensitive * {@code true} if the code should be handled case-sensitively. * * @return * Canonicalized language code. */ static String canonicalize(String code, boolean caseSensitive) { if (code == null || code.length() == 0) { return null; } // Support legacy language codes. Map three obsolete language codes // { "iw", "ji", "in" } to new official ones { "he", "yi", "id" }. final String[] legacy = { "iw", "ji", "in" }; final String[] official = { "he", "yi", "id" }; for (int i = 0; i < legacy.length; ++i) { if (caseSensitive) { if (code.equals(legacy[i])) { return official[i]; } } else { if (code.equalsIgnoreCase(legacy[i])) { return official[i]; } } } if (caseSensitive) { return code; } else { return code.toLowerCase(); } } /** * Get a list of {@code LanguageCode} by a name regular expression. * *

* This method is almost equivalent to {@link #findByName(Pattern) * findByName}{@code (Pattern.compile(regex))}. *

* * @param regex * Regular expression for names. * * @return * List of {@code LanguageCode}. If nothing has matched, * an empty list is returned. * * @throws IllegalArgumentException * {@code regex} is {@code null}. * * @throws java.util.regex.PatternSyntaxException * {@code regex} failed to be compiled. * * @since 1.11 */ public static List findByName(String regex) { if (regex == null) { throw new IllegalArgumentException("regex is null."); } // Compile the regular expression. This may throw // java.util.regex.PatternSyntaxException. Pattern pattern = Pattern.compile(regex); return findByName(pattern); } /** * Get a list of {@code LanguageCode} 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 {@code LanguageCode}s as listed below. *

* *
    *
  1. {@link #an} : Aragonese *
  2. {@link #ja} : Japanese *
  3. {@link #jv} : Javanese *
  4. {@link #su} : Sundanese *
  5. {@link #zh} : Chinese *
* * @param pattern * Pattern to match names. * * @return * List of {@code LanguageCode}. If nothing has matched, * an empty list is returned. * * @throws IllegalArgumentException * {@code pattern} is {@code null}. * * @since 1.11 */ public static List findByName(Pattern pattern) { if (pattern == null) { throw new IllegalArgumentException("pattern is null."); } List list = new ArrayList(); for (LanguageCode entry : values()) { // If the name matches the given pattern. if (pattern.matcher(entry.getName()).matches()) { list.add(entry); } } return list; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy