Annotate Intl with `PropertyKey` (#18371)
Annotate Intl with `PropertyKey`.
This commit is contained in:
parent
a1c8444d24
commit
2937a9b577
|
@ -1,7 +1,10 @@
|
||||||
package eu.kanade.tachiyomi.lib.i18n
|
package eu.kanade.tachiyomi.lib.i18n
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NonNls
|
||||||
|
import org.jetbrains.annotations.PropertyKey
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
|
import java.text.MessageFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.PropertyResourceBundle
|
import java.util.PropertyResourceBundle
|
||||||
|
|
||||||
|
@ -47,7 +50,7 @@ class Intl(
|
||||||
* in the current language, the English value will be returned. If the [key]
|
* 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.
|
* 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)
|
bundle.containsKey(key) -> bundle.getString(key)
|
||||||
baseBundle.containsKey(key) -> baseBundle.getString(key)
|
baseBundle.containsKey(key) -> baseBundle.getString(key)
|
||||||
else -> "[$key]"
|
else -> "[$key]"
|
||||||
|
@ -57,7 +60,8 @@ class Intl(
|
||||||
* Uses the string as a format string and returns a string obtained by
|
* Uses the string as a format string and returns a string obtained by
|
||||||
* substituting the specified arguments, using the instance locale.
|
* 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 =
|
fun languageDisplayName(localeCode: String): String =
|
||||||
Locale.forLanguageTag(localeCode)
|
Locale.forLanguageTag(localeCode)
|
||||||
|
|
Loading…
Reference in New Issue