From 708351fe5e8c91e5bc6e6a257997b660cba51415 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 5 Apr 2008 16:26:40 +0000 Subject: [PATCH] add MessageFormat replacement possibility git-svn-id: http://trooper/svn/projects/jSite/trunk@604 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/jsite/i18n/I18n.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/net/pterodactylus/jsite/i18n/I18n.java b/src/net/pterodactylus/jsite/i18n/I18n.java index b6ff1f7..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; } -- 2.7.4