Example usage for java.util ResourceBundle getBundle

List of usage examples for java.util ResourceBundle getBundle

Introduction

In this page you can find the example usage for java.util ResourceBundle getBundle.

Prototype

@CallerSensitive
public static ResourceBundle getBundle(String baseName, Module module) 

Source Link

Document

Gets a resource bundle using the specified base name and the default locale on behalf of the specified module.

Usage

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
    Enumeration<String> keys = bundle.getKeys();
    ArrayList<String> temp = new ArrayList<String>();

    for (Enumeration<String> e = keys; keys.hasMoreElements();) {
        String key = e.nextElement();
        if (key.startsWith("java2s")) {
            temp.add(key);//w w  w . j a  v  a 2  s  . com
        }
    }

    String[] result = new String[temp.size()];

    for (int i = 0; i < temp.size(); i++) {
        result[i] = bundle.getString(temp.get(i));
    }
    System.out.println(Arrays.toString(result));
}

From source file:Main.java

public static void main(String[] args) {

    ResourceBundle.Control rbc = ResourceBundle.Control.getControl(Control.FORMAT_DEFAULT);

    ResourceBundle bundle = ResourceBundle.getBundle("hello", rbc);

    System.out.println(bundle.getString("hello"));

}

From source file:Animals.java

public static void main(String[] argv) {

    ResourceBundle animalResources;

    try {/*w w  w.j  a v  a2 s .c  om*/
        animalResources = ResourceBundle.getBundle("AnimalResources", Locale.getDefault());
        System.out.println(animalResources.getString("Animals"));
    } catch (MissingResourceException mre) {
        mre.printStackTrace();
    }
}

From source file:RBPropDemo.java

public static void main(String[] args) {
    ResourceBundle.clearCache();// w ww . j  a v  a2  s  . c  o  m
    String bundleName = "myproj.MyResources";

    ResourceBundle myResources = ResourceBundle.getBundle(bundleName, Locale.GERMAN);

    System.out.println("Key's values:");
    System.out.println(myResources.getString("okKey"));
    System.out.println(myResources.getString("cancelKey"));
    System.out.println(myResources.getString("submitKey"));
    System.out.println("\nChecking okKey in resource bundle:");
    if (myResources.containsKey("okKey")) {
        System.out.println("okKey exists! " + " Value = " + myResources.getString("okKey"));
    } else {
        System.out.println("The key Doesn't Exist");
    }

    System.out.println("\nGet a set of keys:");
    Set<String> keySet = myResources.keySet();
    Object[] keys = keySet.toArray();
    for (int i = 0; i < keys.length; i++) {
        System.out.println("Key " + (i + 1) + " = " + keys[i]);
    }
}

From source file:HelloResourceBundleExample.java

  public static void main(String [] argv) {
  try {/*from   w w  w .j  a  va 2 s  . c o m*/
    Locale frenchLocale = new Locale("fr", "FR");
    ResourceBundle rb = ResourceBundle.getBundle("HelloResourceBundle", frenchLocale);

    System.out.println(rb.getString("Hello"));
    System.out.println(rb.getString("Goodbye"));

  } catch (MissingResourceException mre) {
    mre.printStackTrace();
  }
}

From source file:MainClass.java

public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    ResourceBundle rb = ResourceBundle.getBundle("MyResources", locale);
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("I18N Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 2));
    frame.add(new JLabel(rb.getString("userName")));
    frame.add(new JTextField());
    frame.add(new JLabel(rb.getString("password")));
    frame.add(new JPasswordField());
    frame.add(new JButton(rb.getString("login")));
    frame.pack();// www.j a va 2s.c om
    frame.setVisible(true);
}

From source file:JOptionPaneDemonstrationLocalized.java

public static void main(String[] argv) {

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font unicodeFont = new Font("LucidaSans", Font.PLAIN, 12);

        ResourceBundle bundle = ResourceBundle.getBundle("JOptionPaneResources", Locale.getDefault());

        String[] textMessages = new String[3];
        textMessages[0] = bundle.getString("Yes");
        textMessages[1] = bundle.getString("No");
        textMessages[2] = bundle.getString("Cancel");

        JOptionPane jop = new JOptionPane(bundle.getString("MessageText"), JOptionPane.ERROR_MESSAGE,
                JOptionPane.YES_NO_CANCEL_OPTION, null, textMessages);
        JDialog jopDialog = jop.createDialog(null, bundle.getString("TitleText"));
        jop.setFont(unicodeFont);// w  w w  .ja  va2  s . c o  m
        jopDialog.setVisible(true);
        Object userSelection = jop.getValue();
    }

From source file:Main.java

  public static void main(String[] argv) throws Exception {
  Locale locale = Locale.getDefault();
  ResourceBundle rb = ResourceBundle.getBundle("JFileChooser", locale);

  UIManager.put("FileChooser.lookInLabelText", rb.getString("lookInLabelText"));
  UIManager.put("FileChooser.filesOfTypeLabelText", rb.getString("filesOfTypeLabelText"));
  UIManager.put("FileChooser.upFolderToolTipText", rb.getString("upFolderToolTipText"));

}

From source file:RBCPTest.java

public static void main(String[] args) {
    ResourceBundle rb = ResourceBundle.getBundle("resources.XmlRB", Locale.ROOT);
    String type = rb.getString("type");
    System.out.println("Root locale. Key, type: " + type);
    System.out.println();/*from w  w w  . j  av  a 2  s .c o  m*/

    rb = ResourceBundle.getBundle("resources.XmlRB", Locale.JAPAN);
    type = rb.getString("type");
    System.out.println("Japan locale. Key, type: " + type);
    System.out.println();

    test(Locale.CHINA);
    test(new Locale("zh", "HK"));
    test(Locale.TAIWAN);
    test(Locale.CANADA);
}

From source file:XMLResourceBundleControl.java

public static void main(String args[]) {
    ResourceBundle bundle = ResourceBundle.getBundle("Strings", new XMLResourceBundleControl());
    String string = bundle.getString("Key");
    System.out.println("Key: " + string);
}