ResourceBundle: getBundle(String baseName, Locale locale) : ResourceBundle « java.util « Java by API






ResourceBundle: getBundle(String baseName, Locale locale)

 

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

public class Main {

  public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("MessagesBundle", Locale.UK);
    System.out.println("Message in " + Locale.UK + ": " + bundle.getString("greeting"));

    Locale.setDefault(new Locale("in", "ID"));
    bundle = ResourceBundle.getBundle("MessagesBundle");
    System.out.println("Message in " + Locale.getDefault() + ": " + bundle.getString("greeting"));
  }
}
 

Example of our resource bundle files, 

MessagesBundle_en_GB.properties

greeting=Hello, how are you?

MessagesBundle_in_ID.properties

greeting=Halo, apa kabar?

   
  








Related examples in the same category

1.ResourceBundle: getBundle(String baseName)
2.ResourceBundle: getString(String key)