diff --git a/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt b/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt index f2928561d8ed2f056c9e6a90e2f55638f673475f..b50699c108819114964ceb22bcc09b6d8f53ca5a 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt @@ -1,7 +1,9 @@ package org.briarproject.briar.desktop.utils import com.ibm.icu.text.MessageFormat +import mu.KotlinLogging import java.util.Locale +import java.util.MissingResourceException import java.util.ResourceBundle /** @@ -12,30 +14,44 @@ import java.util.ResourceBundle */ object InternationalizationUtils { + private val LOG = KotlinLogging.logger {} + /** * Returns the translated text of the string identified with `key` */ - fun i18n(key: String): String { - val resourceBundle = createResourceBundle() - return resourceBundle.getString(key) - } + fun i18n(key: String): String = + try { + val resourceBundle = createResourceBundle() + resourceBundle.getString(key) + } catch (e: MissingResourceException) { + LOG.warn { "Missing string resource for key '$key'" } + "" + } /** * Returns the translated text of a string with plurals identified with `key` */ - fun i18nP(key: String, amount: Int): String { - val pattern: String = i18n(key) - val messageFormat = MessageFormat(pattern, Locale.getDefault()) - return messageFormat.format(arrayOf(amount)) - } + fun i18nP(key: String, amount: Int): String = + try { + val pattern: String = i18n(key) + val messageFormat = MessageFormat(pattern, Locale.getDefault()) + messageFormat.format(arrayOf(amount)) + } catch (e: IllegalArgumentException) { + LOG.warn { "Pattern does not match arguments for resource '$key' and locale '${Locale.getDefault()}" } + "" + } /** * Returns the translated text of a formatted string with */ - fun i18nF(key: String, vararg params: Any): String { - val pattern: String = i18n(key) - return java.text.MessageFormat.format(pattern, *params) - } + fun i18nF(key: String, vararg params: Any): String = + try { + val pattern: String = i18n(key) + java.text.MessageFormat.format(pattern, *params) + } catch (e: IllegalArgumentException) { + LOG.warn { "Pattern does not match arguments for resource '$key'" } + "" + } /** * Returns the resource bundle used for i18n at Briar Desktop