01: package wilos.resources;
02:
03: import java.util.Locale;
04: import java.util.MissingResourceException;
05: import java.util.ResourceBundle;
06:
07: public class WilosBundle {
08:
09: static private final String BASENAME = "wilos/resources/messages";
10:
11: static private ResourceBundle bundle = ResourceBundle.getBundle(
12: WilosBundle.BASENAME, Locale.getDefault());
13:
14: /**
15: * procedure setCurrentLocale
16: *
17: * @param locale
18: */
19: static public void setCurrentLocale(Locale locale) {
20: if (locale != null) {
21: try {
22: Locale.setDefault(locale);
23: bundle = ResourceBundle.getBundle(WilosBundle.BASENAME,
24: locale);
25: } catch (Exception e) {
26: Locale.setDefault(Locale.ENGLISH);
27: bundle = ResourceBundle.getBundle(WilosBundle.BASENAME,
28: Locale.ENGLISH);
29: }
30: }
31: }
32:
33: /**
34: * function getText
35: *
36: * @param key
37: * @return String : the key in the properties file
38: */
39: static public String getText(String key) {
40: try {
41: return bundle.getString(key);
42: } catch (MissingResourceException e) {
43: return key;
44: }
45: }
46:
47: /**
48: * function getChar
49: *
50: * @param key
51: * @return char: the mnemonic characters
52: */
53: static public char getChar(String key) {
54: return WilosBundle.getText(key).charAt(0);
55: }
56:
57: }
|