From 29b5ba6409b0843b2bd881e605181ecf30464b68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 29 Jun 2011 07:23:46 +0200 Subject: [PATCH] Allow using a message formatter after getting the L10n string from Freenet. --- .../net/pterodactylus/sone/freenet/L10nFilter.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java b/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java index fa7385c..a9d1d72 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java +++ b/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java @@ -17,6 +17,9 @@ package net.pterodactylus.sone.freenet; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import net.pterodactylus.util.template.Filter; @@ -49,7 +52,18 @@ public class L10nFilter implements Filter { */ @Override public String format(TemplateContext templateContext, Object data, Map parameters) { - return l10n.getString(String.valueOf(data)); + List parameterValues = new ArrayList(); + int parameterIndex = 0; + while (parameters.containsKey(String.valueOf(parameterIndex))) { + Object value = parameters.get(String.valueOf(parameterIndex)); + if (((String) value).startsWith("=")) { + value = ((String) value).substring(1); + } else { + value = templateContext.get((String) value); + } + parameterValues.add(value); + ++parameterIndex; + } + return new MessageFormat(l10n.getString(String.valueOf(data))).format(parameterValues.toArray()); } - } -- 2.7.4