import javax.annotation.Nonnull;
-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
* translated equivalents.
*/
public class L10nFilter implements Filter {
- /** The web interface. */
- private final WebInterface webInterface;
+ private final BaseL10n l10n;
- /**
- * Creates a new L10n filter.
- *
- * @param webInterface
- * The Sone web interface
- */
- public L10nFilter(WebInterface webInterface) {
- this.webInterface = webInterface;
+ public L10nFilter(BaseL10n l10n) {
+ this.l10n = l10n;
}
/**
List<Object> parameterValues = getParameters(data, parameters);
String text = getText(data);
if (parameterValues.isEmpty()) {
- return webInterface.getL10n().getString(text);
+ return l10n.getString(text);
}
- return new MessageFormat(webInterface.getL10n().getString(text), new Locale(webInterface.getL10n().getSelectedLanguage().shortCode)).format(parameterValues.toArray());
+ return new MessageFormat(l10n.getString(text), new Locale(l10n.getSelectedLanguage().shortCode)).format(parameterValues.toArray());
}
@Nonnull
private final ElementLoader elementLoader;
private final LinkedElementRenderFilter linkedElementRenderFilter;
private final TimeTextConverter timeTextConverter = new TimeTextConverter();
- private final L10nFilter l10nFilter = new L10nFilter(this);
+ private final L10nFilter l10nFilter;
/** The “new Sone” notification. */
private final ListNotification<Sone> newSoneNotification;
this.elementLoader = elementLoader;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
soneTextParser = new SoneTextParser(getCore(), getCore());
+ l10nFilter = new L10nFilter(getL10n());
templateContextFactory = new TemplateContextFactory();
templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
templateContextFactory.addFilter("html", new HtmlFilter());
templateContextFactory.addFilter("replace", new ReplaceFilter());
templateContextFactory.addFilter("store", new StoreFilter());
- templateContextFactory.addFilter("l10n", new L10nFilter(this));
+ templateContextFactory.addFilter("l10n", l10nFilter);
templateContextFactory.addFilter("substring", new SubstringFilter());
templateContextFactory.addFilter("xml", new XmlFilter());
templateContextFactory.addFilter("change", new RequestChangeFilter());
import freenet.l10n.BaseL10n.LANGUAGE.ENGLISH
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.util.template.TemplateContext
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
*/
class L10nFilterTest {
- private val webInterface = mock<WebInterface>()
- private val filter = L10nFilter(webInterface)
- private val templateContext = mock<TemplateContext>()
private val l10n = mock<BaseL10n>()
+ private val filter = L10nFilter(l10n)
+ private val templateContext = mock<TemplateContext>()
private val translations = mutableMapOf<String, String>()
@Before
- fun setupWebInterface() {
- whenever(webInterface.l10n).thenReturn(l10n)
- }
-
- @Before
fun setupL10n() {
whenever(l10n.selectedLanguage).thenReturn(ENGLISH)
whenever(l10n.getString(anyString())).then { translations[it.arguments[0]] }