Welcome
Welcome to <strong>Developer</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Localization in Java

Discuss Java programming technology.

Localization in Java

Postby developer on Fri Feb 08, 2008 11:09 pm

Localization in Java

Localization is a big issue in current software development.

In Java API, Java provides a Locale class and predefines some Locale constants such as Locale.US, Locale.English for convenience to cope with localization issue. But how about the Locale that Java does not predefine, like PORTUGAL, PORTUGUESE? Do not worry, you can use Locale constructor to construct customized Locale.

In Locale class, there are three constructors:

Code: Select all
Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)


Let's see the third one, then you will know the former two constructors.

The first parameter is language code. It is a lowercase two-letter ISO-639 code. You can find it in http://www.loc.gov/standards/iso639-2/englangn.html.
The second parameter is country code. It is a uppercase two-letter ISO-3166 code. You can find it in http://www.iso.ch/iso/en/prods-services ... t-en1.html.
The third parameter is vendor and browser specific code. For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. Where there are two variants, separate them with an underscore, and put the most important one first. For example, a Traditional Spanish collation might construct a locale with parameters for language, country and variant as: "es", "ES", "Traditional_WIN".

The following is an example of Locale.

Test.java

Code: Select all
public class Test {

    static Locale PORTUGAL = new Locale("pt","PT"); 
   
    public static void main(String[] args) {       
        String s = (PORTUGAL).getDisplayLanguage();
        System.out.println(s);
       
        Currency curr = Currency.getInstance(PORTUGAL);
        System.out.println("Portugal: " + curr.getSymbol());
    }
}


We construct a Locale named PORTUGAL which is not predefined in Locale class as a constant variable.
Then we can use this PORTUGAL locale in other places.
developer
Site Admin
 
Posts: 37
Joined: Thu Jan 31, 2008 8:26 pm

Postby developer on Fri Feb 08, 2008 11:15 pm

Here is a good Locale introduction.

http://java.sun.com/docs/books/tutorial ... reate.html
developer
Site Admin
 
Posts: 37
Joined: Thu Jan 31, 2008 8:26 pm


Return to Java

Who is online

Users browsing this forum: No registered users and 0 guests

cron