Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

ResourceBundle Class

ligangligang Member Posts: 76
I don't quite understand :

ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
......
out.println(rb.getString("cookies.cookies"));
......

What is ResouceBundle ?

Comments

  • jakemcbeerjakemcbeer Member Posts: 10
    ResourceBundle is a class that enables you to read localized values from a properties file.

    In your example LocalStrings.properties is the name of the file, because the ResourceBundle class will look for the properties file with the value that you passed into the constructor as the filename with ".properties" as the extension.

    It contains key=value pairs such as the following...

    name=jim
    street=5th

    If no locale is specified in the constructor, the default one is used, which is the locale the jvm has determined for your machine, where the locale is the country settings your machine is configured to use.

    So, if you write an application that you want to export all over the world with all the varied languages there are, the ResourceBundle lets you store all the text in your application in different properties files that you localize for each country the app. is executed in.

    Each one of those files has a country code in the filename to help the ResourceBundle locate the correct file to load the values from.

    To access the values, you pass the key string into the getString method to return the value associated with it in the properties file, as follows...

    cookies.cookies=blah

    ps, the java api documentation that comes with the jdk explains ResourceBundle class adequately... (java.util.ResourceBundle)

    : I don't quite understand :
    :
    : ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
    : ......
    : out.println(rb.getString("cookies.cookies"));
    : ......
    :
    : What is ResouceBundle ?
    :

Sign In or Register to comment.