Example

In this example, we’ll get display language per locale passed as an argument.

Open Compiler

importjava.util.Locale;publicclassI18NTester{publicstaticvoidmain(String[] args){Locale defaultLocale =Locale.getDefault();Locale enLocale =newLocale("en","US");Locale frLocale =newLocale("fr","FR");Locale esLocale =newLocale("es","ES");System.out.println(defaultLocale.getDisplayLanguage(enLocale));System.out.println(defaultLocale.getDisplayLanguage(frLocale));System.out.println(defaultLocale.getDisplayLanguage(esLocale));}}

Output

It will print the following result.

English
anglais
inglés

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *