X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2FL10nFilter.java;h=16dc9fbe280c169c79cd6e7b6e9e8f602cf3d49c;hp=ef1a183ffe99b54a262257277148115ec4248bc5;hb=c41176c97933de44f2d2df08249429cb427b2978;hpb=ecf753a31601e558b681daab0598009fe9eec99a diff --git a/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java b/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java index ef1a183..16dc9fb 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java +++ b/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java @@ -1,5 +1,5 @@ /* - * FreenetSone - L10nFilter.java - Copyright © 2010 David Roden + * Sone - L10nFilter.java - Copyright © 2010 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,11 +17,15 @@ package net.pterodactylus.sone.freenet; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; import java.util.Map; +import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.util.template.Filter; import net.pterodactylus.util.template.TemplateContext; -import freenet.l10n.BaseL10n; /** * {@link Filter} implementation replaces {@link String} values with their @@ -31,17 +35,17 @@ import freenet.l10n.BaseL10n; */ public class L10nFilter implements Filter { - /** The l10n handler. */ - private final BaseL10n l10n; + /** The web interface. */ + private final WebInterface webInterface; /** * Creates a new L10n filter. * - * @param l10n - * The l10n handler + * @param webInterface + * The Sone web interface */ - public L10nFilter(BaseL10n l10n) { - this.l10n = l10n; + public L10nFilter(WebInterface webInterface) { + this.webInterface = webInterface; } /** @@ -49,7 +53,21 @@ public class L10nFilter implements Filter { */ @Override public String format(TemplateContext templateContext, Object data, Map parameters) { - return l10n.getString(String.valueOf(data)); + if (parameters.isEmpty()) { + return webInterface.getL10n().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(webInterface.getL10n().getString(String.valueOf(data)), new Locale(webInterface.getL10n().getSelectedLanguage().shortCode)).format(parameterValues.toArray()); } - }