Create Locales with Language Name - Java Internationalization

Java examples for Internationalization:Locale

Description

Create Locales with Language Name

Demo Code

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
  public static void main(String[] args) {
    System.out.printf("Creating from BCP 47 language tags...\n\n");
    String[] bcp47LangTags= {"fr-FR", "ja-JP", "en-US"};        
    Locale l = null;//w ww .jav a  2  s.c  om
    for (String langTag: bcp47LangTags) {
        l = Locale.forLanguageTag(langTag);
        displayLocalizedData(l, 123456789L, new Date());        
    }
  }

  private static void displayLocalizedData(Locale l, long number, Date date) {
    NumberFormat nf = NumberFormat.getInstance(l);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
        DateFormat.LONG, l);
    System.out.printf("Locale: %s\nNumber: %s\nDate: %s\n\n",
        l.getDisplayName(), nf.format(number), df.format(date));
  }
}

Result


Related Tutorials