summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java
diff options
context:
space:
mode:
authorMürsel Türk2020-07-07 12:31:53 +0200
committerMürsel Türk2020-07-07 12:31:53 +0200
commitaf5e6f587ccfb68ad5189641d474d3df98a7f7f6 (patch)
treef59802866f1c3505f975df41a4a30fb0981b4458 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java
parent[client] Add resource bundle files for wizard classes. Update the wizard clas... (diff)
downloadtutor-module-af5e6f587ccfb68ad5189641d474d3df98a7f7f6.tar.gz
tutor-module-af5e6f587ccfb68ad5189641d474d3df98a7f7f6.tar.xz
tutor-module-af5e6f587ccfb68ad5189641d474d3df98a7f7f6.zip
[client] Add helper classes for i18n.
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java
new file mode 100644
index 00000000..fe976b59
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/I18n.java
@@ -0,0 +1,50 @@
+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"),
+ CONFIGURATOR("configurator"),
+ CONTROL("control"),
+ HELPER("helper"),
+ PAGE("page"),
+ PAGE_LAYOUT("page_layout"),
+ 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;
+ }
+ }
+} \ No newline at end of file