Package de.Keyle.MyPet.api.util.locale
Class Locale
java.lang.Object
de.Keyle.MyPet.api.util.locale.Locale
- All Implemented Interfaces:
Translator
MyPet's translation facility. Combines two roles:
- Static facade —
getComponent,getFormattedComponent,renderPlain, etc. that callers across the codebase use to look up a translation for a player, command sender, or explicit locale tag. - Adventure
Translatorimplementation — a single instance is registered withGlobalTranslatoroninit(), so that anyComponent.translatable(...)created with a MyPet key resolves through this class regardless of where in the codebase it is rendered.
Bundles are loaded from locale/MyPet_<tag>.properties entries inside
the plugin JAR, with sparse per-key overlay from plugins/MyPet/locale/
files of the same name. Values may contain MiniMessage tags and
{0}/{1}-style placeholders that are substituted with the
arguments passed via TranslatableComponent.arguments().
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringResolves a command sender's locale: the player's client locale forPlayersenders,"en"for console.static ComponentgetComponent(String key, MyPetPlayer player) Renders a translation key against the owner's stored language.static ComponentgetComponent(String key, String localeString) Renders a translation key against an explicit locale.static ComponentgetComponent(String key, CommandSender sender) Renders a translation key against the sender's locale, or English for console.static ComponentgetComponent(String key, Player player) Renders a translation key against the player's client locale.static ComponentgetFormattedComponent(String key, MyPetPlayer player, Object... values) Renders a translation key against the owner's stored language, substituting the given arguments.static ComponentgetFormattedComponent(String key, String localeString, Object... values) Renders a translation key against an explicit locale, substituting the given arguments.static ComponentgetFormattedComponent(String key, CommandSender sender, Object... values) Renders a translation key against the sender's locale, or English for console, substituting the given arguments.static ComponentgetFormattedComponent(String key, Player player, Object... values) Renders a translation key against the player's client locale, substituting the given arguments.static StringgetPlayerLanguage(Player player) Resolves a player's client locale, falling back to"en_us"when Bukkit returns an empty string.static booleanRead-only probe: true if MyPet has a translation forkeyresolvable for the given locale, using the exact same lookup + casing as rendering.static voidinit()Loads all translation bundles and registers this class as a translation source withGlobalTranslator.@NotNull Keyname()static StringrenderPlain(String key, String localeString) Renders a translation key to plain text against the given locale.renderPlainAll(String key) Plain-text renderings ofkeyin every loaded bundle that contains it.@Nullable MessageFormat@Nullable Componenttranslate(@NotNull TranslatableComponent component, Locale locale) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.kyori.adventure.translation.Translator
canTranslate, hasAnyTranslations
-
Method Details
-
init
public static void init()Loads all translation bundles and registers this class as a translation source withGlobalTranslator. Idempotent — safe to call from bothMyPetPlugin.onEnableand/mypet reload; an existing registration is removed before a fresh one is added. -
getPlayerLanguage
Resolves a player's client locale, falling back to"en_us"when Bukkit returns an empty string.- Parameters:
player- the player whose client locale to read- Returns:
- a lower-cased locale tag such as
"en_us"
-
getCommandSenderLanguage
Resolves a command sender's locale: the player's client locale forPlayersenders,"en"for console.- Parameters:
sender- the sender whose locale to read- Returns:
- a lower-cased locale tag
-
getComponent
Renders a translation key against the player's client locale.- Parameters:
key- the translation keyplayer- the reader; anullvalue renders the key itself- Returns:
- the translated component
-
getComponent
Renders a translation key against the sender's locale, or English for console.- Parameters:
key- the translation keysender- the reader; anullvalue renders the key itself- Returns:
- the translated component
-
getComponent
Renders a translation key against the owner's stored language.- Parameters:
key- the translation keyplayer- the reader; anullvalue renders the key itself- Returns:
- the translated component
-
getComponent
Renders a translation key against an explicit locale.- Parameters:
key- the translation keylocaleString- the locale tag to render for- Returns:
- the translated component
-
getFormattedComponent
Renders a translation key against the player's client locale, substituting the given arguments.- Parameters:
key- the translation keyplayer- the reader; anullvalue renders the key itselfvalues- arguments substituted into the translation, in order- Returns:
- the translated component
-
getFormattedComponent
Renders a translation key against the sender's locale, or English for console, substituting the given arguments.- Parameters:
key- the translation keysender- the reader; anullvalue renders the key itselfvalues- arguments substituted into the translation, in order- Returns:
- the translated component
-
getFormattedComponent
Renders a translation key against the owner's stored language, substituting the given arguments.- Parameters:
key- the translation keyplayer- the reader; anullvalue renders the key itselfvalues- arguments substituted into the translation, in order- Returns:
- the translated component
-
getFormattedComponent
Renders a translation key against an explicit locale, substituting the given arguments.- Parameters:
key- the translation keylocaleString- the locale tag to render forvalues- arguments substituted into the translation, in order- Returns:
- the translated component
-
renderPlain
Renders a translation key to plain text against the given locale. Used by call sites that must materialize a translation into a String for storage (e.g. persisted pet names). All styling tags in the translation value are stripped.- Parameters:
key- the translation keylocaleString- the locale tag to render for- Returns:
- the translation as plain text, with all styling removed
-
renderPlainAll
Plain-text renderings ofkeyin every loaded bundle that contains it.- Parameters:
key- the translation key- Returns:
- locale tag to plain-text rendering, for every bundle holding the key
-
hasKey
Read-only probe: true if MyPet has a translation forkeyresolvable for the given locale, using the exact same lookup + casing as rendering. Lets callers fall back before a missing key would surface as a raw translatable. Does not affecttranslate(java.lang.String, java.util.Locale).- Parameters:
key- the translation key to probe forlocaleString- the locale tag to resolve against- Returns:
trueif a translation exists
-
name
- Specified by:
namein interfaceTranslator
-
translate
@Nullable public @Nullable MessageFormat translate(@NotNull @NotNull String key, @NotNull Locale locale) - Specified by:
translatein interfaceTranslator
-
translate
@Nullable public @Nullable Component translate(@NotNull @NotNull TranslatableComponent component, @NotNull Locale locale) - Specified by:
translatein interfaceTranslator
-