Demo of I18N (Internationalization) with JAVA

I18N is called Internationalization, which supports Multiparty language in your software. again its not convert one language to other language but Display selected language from “Properties” file.

Crate I18nDemo.java file Copy the following code.

 

 import java.util.*;
public class I18nDemo {
 private static Locale aLocale;
 private static Locale frLocale;
 private static ResourceBundle Message;
 public static void main(String[] args)
 {
aLocale = new Locale("en","US");
 frLocale = new Locale("fr","FR");
Message = ResourceBundle.getBundle("MessagesBundle",aLocale);
 System.out.println(Message.getString("greetings"));
 }
}

Now..

Create Properties file with name “MessagesBundle.properties” for Default language.(our Default language is EN). put in same folder.

===================MessagesBundle.properties======================

greetings = Hello
farewell = Goodbye
inquiry = How are you?

 

Create new properties file for French Language with “MessagesBundle_fr_FR.properties”

===================MessagesBundle_fr_FR.properties=======================

greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?

Create same file for US English

===================MessagesBundle_en_US.properties=======================

greetings = Hello
farewell = Goodbye
inquiry = How are you?

Now change aLocate to frLocate (visa verse)  compile and run the program.

Share Post