The i18n Cookbook - recipies for a global society

  • java cookbook
  • about the author
Home › Java Internationalization Cookbook › Locales

Java Cookbook

  • Java Internationalization Cookbook
    • Locales
      • How to make a Locale object using language and country arguments
      • How to use a static constant to retrieve a common locale
      • How to get an array of available lLocales
      • Get all ISO language and country codes
      • Get localized display names
      • Create an ICU4J ULocale
    • Dates and Times
    • Numerical Systems
    • Misc
    • Resource Bundles
    • Unicode, Transliteration, and Charactersets

How to make a Locale object using language and country arguments

Problem:

You want to create a representation of your user's language and country.

Solution:

A Java locale represents a unique language and country combination. You create a Locale by specifying an ISO 639 language code and ISO 3166-2 country code in the constructor.

To create a Locale representing the English language:

Locale locale = new Locale("en");

 

To create a Locale representing English as spoken in Great Britain:

Locale locale = new Locale("en","GB");

 

To create a Locale representing English as spoken in Japan using a POSIX variant:

Locale locale = new Locale("en",GB","POSIX");

‹ Locales up How to use a static constant to retrieve a common locale ›
  • Java
  • Locale
  • Printer-friendly version
  • Add new comment

If you are testing any of these recipes in Eclipse and the characters are not displaying correctly in your console visit http://i18ncookbook.com/eclipse_settings.

This site is ad supported.  I hope you find something among our sponsors worth clicking. ;)

i18n search

Google
Custom Search

Search

Tags in Tags

calendar date icu4j Java Locale number format numberformat parse spellout timezone transliteration transliterator
more tags

User login

  • Create new account
  • Request new password
  • java cookbook
  • about the author