Internationalization (I)
23 December 2007Internationalizing Java applications is of great importance if you are planning to develop an application to be used in different parts of the world. In this post, I will try to develop a simple internationalized application.
Different regions of the world have different languages, currency and time zone. Developing a Java application that can be used throughout the world without much changes is the requirement of this age. Internationalized applications are the solution. Internationalized applications can be tailored to the language, currency and time zone of the end users around world.
There are two ways of doing this. One is to hardcode everything into code. Using if then else and switch, you can change language, currency and time zone. This will work fine but the problem is, its not flexible. If you wan to your application to work for a new region, you have to change the code and compile it again. So, this approach is not a good one. Following is an example:
public class HelloWorld { public static void main(String[] args) { String country = new String(args[0]); if(country.equals("US")) { System.out.println("Hello! How are you?"); } else if(country.equals("DE")) { System.out.println("Hallo! Wie gehts?"); } else System.out.println("Country not identified."); } }
Output for DE
Hallo! Wie gehts?
Output for US
Hello! How are you?
The application is producing the required results but its not flexible at all. If we want to introduce a new language support, or want to change the hard coded messages, we have to write the code and have to recompile. This is not the ideal solution.
Ideal way is to use Local and ResourceBundle. I will convert the above example into ideal solution in the next post.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Internationalization (I)