Java - Get a list of all 2-letter language codes defined in ISO 639

Category : Java | Sub Category : Java Programs | By Runner Dev Last updated: 2020-10-20 15:14:51 Viewed : 377


Java  - Get a list of all 2-letter language codes defined in ISO 639

1.   String[] java.util.Locale.getISOLanguages() 

Returns a list of all 2-letter language codes defined in ISO 639. Can be used to create Locales.

Note:

·        ISO 639 is not a stable standard— some languages` codes have changed. The list this function returns includes both the new and the old codes for the languages whose codes have changed.

·        The Locale class also supports language codes up to 8 characters in length. Therefore, the list returned by this method does not contain ALL valid codes that can be used to create Locales.

 

Returns:

Am array of ISO 639 two-letter language codes.

 Java API:

  public static String[] getISOLanguages() {

        if (isoLanguages == null) {

            isoLanguages = getISO2Table(LocaleISOData.isoLanguageTable);

        }

        String[] result = new String[isoLanguages.length];

        System.arraycopy(isoLanguages, 0, result, 0, isoLanguages.length);

        return result;

    }

 

2.   Example:

Following example illustrates about Java -list of all 2-letter language codes  

Save the file as −  LanguageCode.java

 

       package runnerdev; 

import java.util.HashMap;

import java.util.Locale;

import java.util.Map;

 

public class LanguageCode {

static Map<String, String> map = new HashMap<String, String>();

 

     public static void main(String args[]) {

           String[] languages = Locale.getISOLanguages();

           for (int i = 0; i < languages.lengthi++) {

                Locale loc = new Locale(languages[i]);

 map.put(loc.getLanguage().toUpperCase(), loc.getDisplayLanguage());

           }

           System.out.println(“print language codes and names:”)

           System.out.println(map);

 

           // System.out.println(“print only language codes:”)

           map.keySet().forEach(langCode -> {

                System.out.println(langCode);

           });

     } 

 }                                                   

 compile and run the above Java example as follows 

> javac LanguageCode.java

java LanguageCode

 

OutPut:

print language codes and names:

{HI=Hindi, PS=Pushto, PT=Portuguese, HO=Hiri Motu, HR=Croatian, HT=Haitian, HU=Hungarian, HY=Armenian, HZ=Herero, YO=Yoruba, IA=Interlingua, IE=Interlingue, IG=Igbo, AA=Afar, II=Sichuan Yi, AB=Abkhazian, IK=Inupiaq, AE=Avestan, QU=Quechua, AF=Afrikaans, IN=Indonesian, IO=Ido, ZA=Zhuang, AK=Akan, IS=Icelandic, IT=Italian, AM=Amharic, IU=Inuktitut, AN=Aragonese, IW=Hebrew, ZH=Chinese, AR=Arabic, AS=Assamese, AV=Avaric, JA=Japanese, AY=Aymara, AZ=Azerbaijani, RM=Raeto-Romance, ZU=Zulu, RN=Rundi, RO=Romanian, BA=Bashkir, JI=Yiddish, BE=Belarusian, RU=Russian, BG=Bulgarian, RW=Kinyarwanda, BH=Bihari, BI=Bislama, BM=Bambara, BN=Bengali, JV=Javanese, BO=Tibetan, SA=Sanskrit, BR=Breton, SC=Sardinian, BS=Bosnian, SD=Sindhi, SE=Northern Sami, SG=Sango, KA=Georgian, SI=Sinhalese, SK=Slovak, SL=Slovenian, SM=Samoan, SN=Shona, KG=Kongo, SO=Somali, CA=Catalan, KI=Kikuyu, SQ=Albanian, KJ=Kwanyama, SR=Serbian, KK=Kazakh, SS=Swati, KL=Greenlandic, ST=Southern Sotho, CE=Chechen, KM=Khmer, SU=Sundanese, KN=Kannada, SV=Swedish, KO=Korean, SW=Swahili, CH=Chamorro, KR=Kanuri, KS=Kashmiri, KU=Kurdish, KV=Komi, CO=Corsican, KW=Cornish, TA=Tamil, KY=Kirghiz, CR=Cree, CS=Czech, TE=Telugu, CU=Church Slavic, CV=Chuvash, TG=Tajik, TH=Thai, LA=Latin, TI=Tigrinya, CY=Welsh, LB=Luxembourgish, TK=Turkmen, TL=Tagalog, TN=Tswana, LG=Ganda, TO=Tonga, DA=Danish, LI=Limburgish, TR=Turkish, TS=Tsonga, TT=Tatar, DE=German, LN=Lingala, LO=Lao, TW=Twi, TY=Tahitian, LT=Lithuanian, LU=Luba-Katanga, LV=Latvian, DV=Divehi, UG=Uighur, DZ=Dzongkha, UK=Ukrainian, MG=Malagasy, MH=Marshallese, MI=Maori, UR=Urdu, MK=Macedonian, ML=Malayalam, EE=Ewe, MN=Mongolian, MO=Moldavian, MR=Marathi, UZ=Uzbek, MS=Malay, EL=Greek, MT=Maltese, EN=English, EO=Esperanto, MY=Burmese, ES=Spanish, ET=Estonian, VE=Venda, EU=Basque, NA=Nauru, VI=Vietnamese, NB=Norwegian Bokmål, ND=North Ndebele, NE=Nepali, NG=Ndonga, VO=Volapük, FA=Persian, NL=Dutch, FF=Fulah, NN=Norwegian Nynorsk, NO=Norwegian, FI=Finnish, FJ=Fijian, NR=South Ndebele, NV=Navajo, FO=Faroese, WA=Walloon, NY=Nyanja, FR=French, FY=Frisian, OC=Occitan, WO=Wolof, GA=Irish, OJ=Ojibwa, GD=Scottish Gaelic, OM=Oromo, OR=Oriya, OS=Ossetian, GL=Gallegan, GN=Guarani, GU=Gujarati, GV=Manx, XH=Xhosa, PA=Panjabi, HA=Hausa, PI=Pali, PL=Polish}

 

print only language codes:

HI

PS

PT

HO

HR

HT

HU

HY

HZ

YO

IA

IE

IG

AA

II

AB

IK

AE

QU

AF

IN

IO

ZA

AK

IS

IT

AM

IU

AN

IW

ZH

AR

AS

AV

JA

AY

AZ

RM

ZU

RN

RO

BA

JI

BE

RU

BG

RW

BH

BI

BM

BN

JV

BO

SA

BR

SC

BS

SD

SE

SG

KA

SI

SK

SL

SM

SN

KG

SO

CA

KI

SQ

KJ

SR

KK

SS

KL

ST

CE

KM

SU

KN

SV

KO

SW

CH

KR

KS

KU

KV

CO

KW

TA

KY

CR

CS

TE

CU

CV

TG

TH

LA

TI

CY

LB

TK

TL

TN

LG

TO

DA

LI

TR

TS

TT

DE

LN

LO

TW

TY

LT

LU

LV

DV

UG

DZ

UK

MG

MH

MI

UR

MK

ML

EE

MN

MO

MR

UZ

MS

EL

MT

EN

EO

MY

ES

ET

VE

EU

NA

VI

NB

ND

NE

NG

VO

FA

NL

FF

NN

NO

FI

FJ

NR

NV

FO

WA

NY

FR

FY

OC

WO

GA

OJ

GD

OM

OR

OS

GL

GN

GU

GV

XH

PA

HA

PI

PL

Search
Related Articles

Leave a Comment: