X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fi18n%2FI18n.java;h=db97d0bcdffe06a8c90ac81b9e25fb3ed61a0830;hb=c8ae24a9e5cdfe22096b56f0108f8d92fe3cbd11;hp=4a244c5c9f9d7a7167b1e34f26ddd50b988ce9d4;hpb=b6fa9b11b319a9fda7376be5f4818efafe5a78b2;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/i18n/I18n.java b/src/net/pterodactylus/jsite/i18n/I18n.java index 4a244c5..db97d0b 100644 --- a/src/net/pterodactylus/jsite/i18n/I18n.java +++ b/src/net/pterodactylus/jsite/i18n/I18n.java @@ -24,6 +24,7 @@ import java.awt.event.KeyEvent; 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; @@ -65,19 +66,27 @@ public class I18n { } /** - * 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; } @@ -136,7 +145,6 @@ public class I18n { 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. */ @@ -148,7 +156,6 @@ public class I18n { /* ignore. */ } } - System.out.println("asked for: “" + key + "”, will return " + keyToken.charAt(0)); return KeyStroke.getKeyStroke(keyToken.charAt(0), modifierMask); } }