Rename some elements to make meaning clearer
This commit is contained in:
@@ -14,10 +14,10 @@ import kotlin.collections.HashMap
|
|||||||
* `messages_locale.properties`, where `locale` is formatted as returned by
|
* `messages_locale.properties`, where `locale` is formatted as returned by
|
||||||
* [Locale.toString].
|
* [Locale.toString].
|
||||||
*/
|
*/
|
||||||
object L10n {
|
object Localization {
|
||||||
/**
|
/**
|
||||||
* This function determines which locale is used for a player, by default
|
* This function determines which locale is used for a player, by default
|
||||||
* [Locale.US] is returned.
|
* [Locale.US] is always returned.
|
||||||
*
|
*
|
||||||
* It is invoked every time a message is localized, so some sort of caching
|
* It is invoked every time a message is localized, so some sort of caching
|
||||||
* is advisable in many cases.
|
* is advisable in many cases.
|
||||||
@@ -32,7 +32,7 @@ object L10n {
|
|||||||
* @throws MissingResourceException if no messages exist for the given
|
* @throws MissingResourceException if no messages exist for the given
|
||||||
* locale or [key] was not found in the messages
|
* locale or [key] was not found in the messages
|
||||||
*/
|
*/
|
||||||
fun getMessage(locale: Locale, key: String): String =
|
fun get(locale: Locale, key: String): String =
|
||||||
getOrLoadBundle(locale)?.getString(key) ?: throw MissingResourceException(
|
getOrLoadBundle(locale)?.getString(key) ?: throw MissingResourceException(
|
||||||
"Messages for locale '$locale' not found", "ResourceBundle", key
|
"Messages for locale '$locale' not found", "ResourceBundle", key
|
||||||
)
|
)
|
||||||
@@ -41,9 +41,9 @@ object L10n {
|
|||||||
* Additionally formats the localized string with the named [args], which
|
* Additionally formats the localized string with the named [args], which
|
||||||
* are represented as `{argumentName}` in the translations
|
* are represented as `{argumentName}` in the translations
|
||||||
*/
|
*/
|
||||||
fun getMessage(locale: Locale, key: String, vararg args: Pair<String, Any?>): String =
|
fun get(locale: Locale, key: String, vararg args: Pair<String, Any?>): String =
|
||||||
StrSubstitutor.replace(
|
StrSubstitutor.replace(
|
||||||
getMessage(locale, key),
|
get(locale, key),
|
||||||
mapOf(*args),
|
mapOf(*args),
|
||||||
"{", "}"
|
"{", "}"
|
||||||
)
|
)
|
||||||
@@ -64,15 +64,15 @@ object L10n {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the localized message using the locale provided by
|
* Returns the localized message using the locale provided by
|
||||||
* [L10n.localeProvider]
|
* [Localization.localeProvider]
|
||||||
*
|
*
|
||||||
* @see L10n.getMessage
|
* @see Localization.get
|
||||||
*/
|
*/
|
||||||
fun Player.getMessage(key: String) =
|
fun Player.localize(key: String) =
|
||||||
L10n.getMessage(L10n.localeProvider(this), key)
|
Localization.get(Localization.localeProvider(this), key)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see L10n.getMessage
|
* @see Localization.get
|
||||||
*/
|
*/
|
||||||
fun Player.getMessage(key: String, vararg args: Pair<String, Any?>) =
|
fun Player.localize(key: String, vararg args: Pair<String, Any?>) =
|
||||||
L10n.getMessage(L10n.localeProvider(this), key, *args)
|
Localization.get(Localization.localeProvider(this), key, *args)
|
Reference in New Issue
Block a user