Java Reference
In-Depth Information
public abstract Enumeration getKeys()
Returns an Enumeration of the keys understood by this bundle,
including all those of the parent.
Each resource bundle defines a set of string keys that map to locale-
sensitive resources. These strings can be anything you like, although it
is best to make them mnemonic. When you want to use the resource
you look it up by name. If the resource is not found a MissingResourceEx-
ception is thrown. The resources themselves can be of any type but are
commonly strings, so the getString methods are provided for conveni-
ence.
The following example shows an internationalized way to rewrite the
"Hello, world" example. This internationalized version requires a pro-
gram called GlobalHello and a resource bundle for the program's strings
called GlobalRes , which will define a set of constants for the localizable
strings. First, the program:
import java.util.*;
public class GlobalHello {
public static void main(String[] args) {
ResourceBundle res =
ResourceBundle.getBundle("GlobalRes");
String msg;
if (args.length > 0)
msg = res.getString(GlobalRes.GOODBYE);
else
msg = res.getString(GlobalRes.HELLO);
System.out.println(msg);
}
}
The program first gets its resource bundle. Then it checks whether any
arguments are provided on the command line. If some are, it says good-
bye; otherwise it says hello. The program logic determines which mes-
 
Search WWH ::




Custom Search