From 2937a9b577868bfa6c58c44cd214bddb9035a870 Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:48:32 -0300 Subject: [PATCH] Annotate Intl with `PropertyKey` (#18371) Annotate Intl with `PropertyKey`. --- .../src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt b/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt index 7899da8ca..aa6e9bf12 100644 --- a/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt +++ b/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt @@ -1,7 +1,10 @@ package eu.kanade.tachiyomi.lib.i18n +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.PropertyKey import java.io.InputStreamReader import java.text.Collator +import java.text.MessageFormat import java.util.Locale import java.util.PropertyResourceBundle @@ -47,7 +50,7 @@ class Intl( * in the current language, the English value will be returned. If the [key] * is also not present in English, the [key] surrounded by brackets will be returned. */ - operator fun get(key: String): String = when { + operator fun get(@PropertyKey(resourceBundle = "i18n.messages") key: String): String = when { bundle.containsKey(key) -> bundle.getString(key) baseBundle.containsKey(key) -> baseBundle.getString(key) else -> "[$key]" @@ -57,7 +60,8 @@ class Intl( * Uses the string as a format string and returns a string obtained by * substituting the specified arguments, using the instance locale. */ - fun format(key: String, vararg args: Any?) = get(key).format(locale, *args) + fun format(@PropertyKey(resourceBundle = "i18n.messages") key: String, vararg args: Any?) = + get(key).format(locale, *args) fun languageDisplayName(localeCode: String): String = Locale.forLanguageTag(localeCode)