A locale is an identifier for a particular combination of language and country. In Java, a locale contains cultural information such as date/time format, number format, and currency format. A locale object is used as an argument in other java classes that need to perform locale specific operations.
By default, java determines the default locale by detecting the system locale of the operating system it is running with. The th_TH locale is the default locale for Thai when the java application runs on a Thai operating system. However, a different locale can be assigned in Java by using the –D option with the user.language and the user.region system properties when JVM starts up. For example, to run a java application with th_TH locale you can do:
java -Duser.language=th -Duser.region=TH JavaApp

Figure 1: Thai locale information. Click on the image to display full-size.
In Java 2 platform, new Thai support has been implemented on Thai locales:
- Buddhist Calendar support
- Thai digit support
- Thai collation support
Buddhist Calendar support
In Thailand, Buddhist calendar is the official calendar and is widely used in the calendar system. Western digits is mostly used in general, however, we find that the government organizations use Thai digits with the Buddhist calendar.
In Java, Buddhist calendar support in date format has been introduced since JDK 1.4. It is the default calendar for Thai locales (th_TH and th_TH_TH). See the list of supported calendar according to Thai locales.
|
Locale
|
Calendar
|
|
th_US
|
Gregorian calendar with Western digits
|
|
th_TH
|
Buddhist calendar with Western digits (JDK 1.4 or higher)
|
|
th_TH_TH
|
Buddhist calendar with Thai digits (JDK 1.4.1 or higher)
|
Table 1: Supported calendar for Thai locales.
Below is an example date format in short/middle/long/full style patterns:

Table 2: Thai date format in various patterns. Click on the image to display full-size
Thai digit
In Thailand, Thai government encourages Thai people to use Thai digits instead of Western digits. Java 1.4.1 or higher provides th_TH_TH locales for Thai digit support. Mostly, Thai digits are used for display purposes only. Even if Java can recognize Thai digits as a number, the mathematic operations using Thai digits are seldom used in Thai applications.
Thai collation
For collation solutions, java provides the abstract locale-sensitive class, java.text.Collator, to collate strings according to the locale specific rules. Thai standard collation rules are conformed to the Thai Royal Institute Dictionary and to collate Thai string in the way that conforms to the Thai Royal Institute Dictionary rules, Thai locale must be passed as the argument of Collator.getInstance (Locale) method.
Collator collate = Collator.getInstance (new Locale (“th”, “TH”));
Once you get the Collator instance, you can compare Thai text string with Collator class’s methods in the several ways.
-
Use either the Collator.compare (String, String) or Collator.equals(Object) methods to compare two strings.
-
Use the Collator.getCollationKey (String) methods for better performance to sort a list of the multiple strings.
Thai collation results from Java API are very adequate. However, there is one concern when using collation with Thai data. Practically, data source may include Thai strings that contain invalid character sequences (For example, consonant + tone mark + vowel). Collation API does not handle invalid Thai data correctly. It sometimes generates an inconsistent result. So, ensure that the input string is a valid character sequence before doing a collation.
|