The i18n Cookbook - recipies for a global society

  • java cookbook
  • about the author
Home

Java Cookbook

  • Java Internationalization Cookbook

Java

Get all time zone ids

Problem:

You want to know what time zones are available on your system.

Solution:

Java uses the TimeZone class to handle date/time casting to and from UTC.  A TimeZone is retrieved by specifying a string id.  Most of these ids are Olsen time zone ids.  You can retrieve an array of time zone ids by calling the static getAvailableIDs() method.

 

To get all available IDs:

  • Java
  • timezone
  • Add new comment
  • Read more

Create an ICU4J ULocale

Problem:

You want more options and power than provided by a core Java locale.

Solution:

ICU4J provides a locale class that provides significantly more capabilites than the Locale class in core Java.  ULocale is the foundation of all internationalization classes in ICU4J.

 

ULocale is defined with at minimum a language code.  It can also contain script name, region code, and other locale specific meta data such as calendar type.

 

To get an English ULocale:

  • icu4j
  • Java
  • Locale
  • ulocale
  • Add new comment
  • Read more

Convert text from one script to another

Problem:

You want to convert the script text is written in.

Solution:

The Transliterator from icu4j class allows for easy conversion of text from one writing system to another.  To transliterate text you simply get an instance of the Transliterator class using the id of the writing system you are converting from, and the id of the system you want to convert into, and then call the transliterate method on the object.

 

  • Java
  • transliterate
  • transliterator
  • Add new comment
  • Read more

Get available target ids for a Transliterator source id

Problem:

You have a source id but you want to retrieve all available target ids for the source id.

Solution:

A Transliterator is retrieved using an id that is a combination of a source and target id.

 

  • Java
  • transliterator
  • Add new comment
  • Read more

Get Transliterators available source ids

Problem:

You want to retireve all available source ids for a Transliterator.

Solution:

A Transliterator is created using a combination of a source and a target id joined by a hyphen. 

To get a list of all sources:

  • Java
  • transliterator
  • Add new comment
  • Read more

Get all available transliterator ids

Problem:

You want to get all available transliterator ids.

Solution:

You obtain a Transliterator by specifying an id.  The id is a String that contains two script names separated by a hyphen, for example: "Latin-Hangul."

 

To obtain a list of all ids:

  • Java
  • transliteration
  • transliterator
  • Add new comment
  • Read more

Parse a formatted date string

Problem:

You want to parse a localized date string to a Java Date.

Solution:

As important as date formatting is, you have to be able to parse the formatted dates.  Parsing a date is very similar to formatting the date.  You just call the parse method on a DateFormat instance.

 

  • date
  • Java
  • parse
  • Add new comment
  • Read more

Get an array of day names

 Problem:

You want to retrieve all of the day of the week names for a locale.

Solution:

The DateFormatSymbols class contains a wealth of information useful to the localization programmer.  You can easily retrieve day names, month names, era names, etc...

 

To get the days of the week in Korean and English:

//Get a DateFormatSymbols object using a locale as an argument

DateFormatSymbols dfsKorean = new DateFormatSymbols(Locale.KOREAN);

  • date
  • DateFormatSymbols
  • day names
  • Java
  • Add new comment
  • Read more

Hebrew Calendar

 Problem:

You want to use a Hebrew Calendar in your application.

Solution:

The Hebrew calendar is a very interesting lunar-solar calendar that poses some interesting challenges for the pogrammer.  It uses a leap month to synch the lunar and solar components.  The first day of the year can vary depending upon how it will affect jewish holidays, and the day ends at sundown.

 

  • calendar
  • hebrew calendar
  • icu4j
  • Java
  • ulocale
  • Add new comment
  • Read more

Japanese Calendar

 Problem:

You want a calendar that is most familiar to your Japanese users.

Solution:

The Japanese calendar is identical to the Gregorian calendar, except the year is represented by the year of the emperor's reign.  It is currently the 20th year of the Heisei emperor's reign, so the year is Heisei 20.

You can create a Japanese calendar by using icu4j .

To create a calendar object:

  • calendar
  • icu4j
  • japanese calendar
  • Java
  • Add new comment
  • Read more
  • 1
  • 2
  • next ›
  • last »

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
Syndicate content

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