Menus

Jun 7, 2016

Java Internationalization Example

  1. Create a folder I18N
  2. Goto above folder from command prompt
  3. Create a java class named I18NSample.java which is as follows:
import java.util.*;
public class I18NSample{
        static public void main(String args[]){
            String language;
            String country;
            //if(args.length!=2){
                language="en";
                country="US";
            //}else{
               // language=args[0];
                //country=args[1];
           // }

            Locale currentLocale;
            ResourceBundle messages;
            currentLocale=new Locale(language,country);
            messages=ResourceBundle.getBundle("MessagesBundle",currentLocale);
            System.out.println(messages.getString("greetings"));
           
        }
}

4. In the same folder create a file named MessagesBundle_en_US.properties and put bellow line inside the file:
greetings=hello

5. Compile I18NSample.java from command prompt:
Javac I18NSample.java
Java I18NSample

Thanks for reading
Happy Coding 

No comments:

Post a Comment

Contact Form

Name

Email *

Message *