From: David ‘Bombe’ Roden Date: Wed, 29 Jun 2011 05:23:46 +0000 (+0200) Subject: Allow using a message formatter after getting the L10n string from Freenet. X-Git-Tag: 0.6.6^2~50 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=29b5ba6409b0843b2bd881e605181ecf30464b68;p=Sone.git Allow using a message formatter after getting the L10n string from Freenet. --- 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()); } - }