From c41176c97933de44f2d2df08249429cb427b2978 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 1 Mar 2012 22:49:16 +0100 Subject: [PATCH] =?utf8?q?Always=20get=20the=20current=20l10n=20helper=20f?= =?utf8?q?rom=20the=20node,=20don=E2=80=99t=20reuse=20an=20old=20one.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This will allow switching the language completely. --- .../net/pterodactylus/sone/freenet/L10nFilter.java | 18 +++++++++--------- .../java/net/pterodactylus/sone/web/WebInterface.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java b/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java index 910e0d6..16dc9fb 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java +++ b/src/main/java/net/pterodactylus/sone/freenet/L10nFilter.java @@ -23,9 +23,9 @@ 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 @@ -35,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; } /** @@ -54,7 +54,7 @@ public class L10nFilter implements Filter { @Override public String format(TemplateContext templateContext, Object data, Map parameters) { if (parameters.isEmpty()) { - return l10n.getString(String.valueOf(data)); + return webInterface.getL10n().getString(String.valueOf(data)); } List parameterValues = new ArrayList(); int parameterIndex = 0; @@ -68,6 +68,6 @@ public class L10nFilter implements Filter { parameterValues.add(value); ++parameterIndex; } - return new MessageFormat(l10n.getString(String.valueOf(data)), new Locale(l10n.getSelectedLanguage().shortCode)).format(parameterValues.toArray()); + return new MessageFormat(webInterface.getL10n().getString(String.valueOf(data)), new Locale(webInterface.getL10n().getSelectedLanguage().shortCode)).format(parameterValues.toArray()); } } diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 109a972..53b9f3b 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -243,7 +243,7 @@ public class WebInterface implements CoreListener { templateContextFactory.addFilter("html", new HtmlFilter()); templateContextFactory.addFilter("replace", new ReplaceFilter()); templateContextFactory.addFilter("store", new StoreFilter()); - templateContextFactory.addFilter("l10n", new L10nFilter(getL10n())); + templateContextFactory.addFilter("l10n", new L10nFilter(this)); templateContextFactory.addFilter("substring", new SubstringFilter()); templateContextFactory.addFilter("xml", new XmlFilter()); templateContextFactory.addFilter("change", new RequestChangeFilter()); -- 2.7.4