import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
+import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Properties;
}
/**
- * Returns the translated value for a key.
+ * Returns the translated value for a key. The translated values may contain
+ * placeholders that are replaced with the given parameters.
*
+ * @see MessageFormat
* @param key
* The key to get
+ * @param parameters
+ * The parameters in case the translated value contains
+ * placeholders
* @return The translated message, or the key itself if no translation could
* be found
*/
- public static String get(String key) {
+ public static String get(String key, Object... parameters) {
String value = null;
value = currentLanguage.getProperty(key);
if (value == null) {
return key;
}
+ if ((parameters != null) && (parameters.length > 0)) {
+ return MessageFormat.format(value, parameters);
+ }
return value;
}
if (keyToken.startsWith("VK_")) {
try {
Field field = KeyEvent.class.getField(keyToken);
- System.out.println("asked for: “" + key + "”, will return " + field.getInt(null));
return KeyStroke.getKeyStroke(field.getInt(null), modifierMask);
} catch (SecurityException e) {
/* ignore. */
/* ignore. */
}
}
- System.out.println("asked for: “" + key + "”, will return " + keyToken.charAt(0));
return KeyStroke.getKeyStroke(keyToken.charAt(0), modifierMask);
}
}