English 中文(简体)
JAVA I18N - Display Language
  • 时间:2024-12-22

Java Internapzation - Locale Language


Previous Page Next Page  

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

I18NTester.java

import java.util.Locale;

pubpc class I18NTester {
   pubpc static void main(String[] args) {
      Locale defaultLocale = Locale.getDefault();
      Locale enLocale = new Locale("en", "US");  
      Locale frLocale = new Locale("fr", "FR");  
      Locale esLocale = new Locale("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.

Engpsh
anglais
inglés
Print