Package net.kyori.adventure.translation
Interface Translator
-
- All Known Subinterfaces:
GlobalTranslator,TranslationRegistry
public interface TranslatorA message translator.To see how to create a
Translatorwith aResourceBundleseeTranslationRegistry.registerAll(Locale, ResourceBundle, boolean)To bypass vanilla's
MessageFormat-based translation system, seetranslate(TranslatableComponent, Locale)After creating a
Translatoryou can add it to theGlobalTranslatorto enable automatic translations by the platforms.- Since:
- 4.0.0
- See Also:
TranslationRegistry
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default @NotNull TriStatehasAnyTranslations()Checks if this translator has any translations.@NotNull Keyname()A key identifying this translation source.static @Nullable java.util.LocaleparseLocale(@NotNull java.lang.String string)Parses aLocalefrom aString.@Nullable java.text.MessageFormattranslate(@NotNull java.lang.String key, @NotNull java.util.Locale locale)Gets a message format from a key and locale.default @Nullable Componenttranslate(@NotNull TranslatableComponent component, @NotNull java.util.Locale locale)Gets a translated component from a translatable component and locale.
-
-
-
Method Detail
-
parseLocale
@Nullable static @Nullable java.util.Locale parseLocale(@NotNull @NotNull java.lang.String string)Parses aLocalefrom aString.- Parameters:
string- the string- Returns:
- a locale
- Since:
- 4.0.0
-
name
@NotNull @NotNull Key name()
A key identifying this translation source.Intended to be used for display to users.
- Returns:
- an identifier for this translation source
- Since:
- 4.0.0
-
hasAnyTranslations
@NotNull default @NotNull TriState hasAnyTranslations()
Checks if this translator has any translations.- Returns:
TriState.TRUEif any,TriState.NOT_SETif unknown, orTriState.FALSEif none- Since:
- 4.15.0
-
translate
@Nullable @Nullable java.text.MessageFormat translate(@NotNull @NotNull java.lang.String key, @NotNull @NotNull java.util.Locale locale)Gets a message format from a key and locale.When used in the
GlobalTranslator, this method is called only iftranslate(TranslatableComponent, Locale)returnsnull.- Parameters:
locale- a localekey- a translation key- Returns:
- a message format or
nullto skip translation - Since:
- 4.0.0
-
translate
@Nullable default @Nullable Component translate(@NotNull @NotNull TranslatableComponent component, @NotNull @NotNull java.util.Locale locale)
Gets a translated component from a translatable component and locale.- Parameters:
locale- a localecomponent- a translatable component- Returns:
- a translated component or
nullto usetranslate(String, Locale)instead (if available) - Since:
- 4.13.0
-
-