Pin It

How do I use locales and resource bundles to internationalize my application?

Program to demonstrate how do I use locales and resource bundles to internationalize my application

package com.hubberspot.example;

import java.util.Locale;
import java.util.ResourceBundle;

public class Properties {

   public static void main(String[] args) {
 // Create a ResourceBundle by calling getBundle()
 // method and passing two parameters, properties file and 
 // Locale to which we want to internationalize
 ResourceBundle resource_en_US = ResourceBundle.
   getBundle("Bundle", new Locale("en","US"));
 // calling getString() and passing the string we want to get
 System.out.println("Message in " + Locale.US + " : " + 
   resource_en_US.getString("welcome"));

 ResourceBundle resource_pt_BR = ResourceBundle.
   getBundle("Bundle", new Locale("pt","BR"));
 System.out.println("Message in " + new Locale("pt","BR")+ " : " + 
   resource_pt_BR.getString("welcome"));

   }

}






Properties file : 


















Output of the program : 





Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot