X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2FL10nFilter.kt;h=65ccbb68b603bec5c093340db0c2a5ef858a96f1;hp=4b0d90f373920bfb1632e749aeafe0d7d66e7795;hb=2f1e414e86c61435cd8b3991c475e0832f6de2fb;hpb=b1f3c46e6c76d216b70733c334642f87187676a9 diff --git a/src/main/kotlin/net/pterodactylus/sone/freenet/L10nFilter.kt b/src/main/kotlin/net/pterodactylus/sone/freenet/L10nFilter.kt index 4b0d90f..65ccbb6 100644 --- a/src/main/kotlin/net/pterodactylus/sone/freenet/L10nFilter.kt +++ b/src/main/kotlin/net/pterodactylus/sone/freenet/L10nFilter.kt @@ -1,5 +1,5 @@ /* - * Sone - L10nFilter.java - Copyright © 2010–2019 David Roden + * Sone - L10nFilter.kt - Copyright © 2010–2019 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,24 +17,22 @@ package net.pterodactylus.sone.freenet -import freenet.l10n.* import net.pterodactylus.util.template.* import java.text.* -import java.util.* /** * [Filter] implementation replaces [String] values with their * translated equivalents. */ -class L10nFilter(private val l10n: BaseL10n) : Filter { +class L10nFilter(private val translation: Translation) : Filter { override fun format(templateContext: TemplateContext?, data: Any?, parameters: Map?): String { val parameterValues = getParameters(data, parameters) val text = getText(data) return if (parameterValues.isEmpty()) { - l10n.getString(text) + translation.translate(text) } else - MessageFormat(l10n.getString(text), Locale(l10n.selectedLanguage.shortCode)).format(parameterValues.toTypedArray()) + MessageFormat(translation.translate(text), translation.currentLocale).format(parameterValues.toTypedArray()) } private fun getText(data: Any?) = (data as? L10nText)?.text ?: data.toString()