1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package org.openslx.dozmod.gui.helper;
import org.apache.log4j.Logger;
import java.text.MessageFormat;
import java.util.ResourceBundle;
/**
* Helper enum for loading resource bundle files and getting values from them.
*/
public enum I18n {
ACTIVITY("activity"),
APP("app"),
CONFIGURATOR("configurator"),
CONTROL("control"),
HELPER("helper"),
GUI("gui"),
PAGE("page"),
PAGE_LAYOUT("page_layout"),
THRIFT("thrift"),
WINDOW("window"),
WINDOW_LAYOUT("window_layout"),
WIZARD("wizard");
/**
* Logger for this class
*/
private final static Logger LOGGER = Logger.getLogger(I18n.class);
private final ResourceBundle resourceBundle;
I18n(String bundleFilename) {
String baseName = "i18n." + bundleFilename;
resourceBundle = ResourceBundle.getBundle(baseName, new UTF8Control());
}
/**
* Returns i18n value for a given key and format the output at the appropriate places for (a) given parameter(s).
* If no key is found, return the key.
* @param key to get value
* @param params to get formatted output
* @return value represented by key or key on error
*/
public String getString(String key, Object... params) {
try {
String value = resourceBundle.getString(key);
return MessageFormat.format(value, params);
} catch (Exception e) {
LOGGER.error("Could not find a value for the given key: " + key);
return key;
}
}
}
|