Class AbstractTranslationStore<T>

java.lang.Object
net.kyori.adventure.translation.AbstractTranslationStore<T>
Type Parameters:
T - the value of the translation store
All Implemented Interfaces:
TranslationStore<T>, Translator, net.kyori.examination.Examinable
Direct Known Subclasses:
AbstractTranslationStore.StringBased

public abstract class AbstractTranslationStore<T> extends Object implements net.kyori.examination.Examinable, TranslationStore<T>
An abstraction to ease the construction of translation stores with generic values.
Since:
4.20.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An abstract, string-based translation store.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new abstract translation store with a given name.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    canTranslate(@NotNull String key, @NotNull Locale locale)
    Checks if this translator can translate the given key and locale pair.
    final boolean
    contains(@NotNull String key)
    Checks if any translations are explicitly registered for the specified key.
    final boolean
    contains(@NotNull String key, @NotNull Locale locale)
    Checks if any translations are explicitly registered for the specified key and locale.
    final void
    defaultLocale(@NotNull Locale locale)
    Sets the default locale used by this store.
    final boolean
    equals(Object other)
     
    final @NotNull Stream<? extends net.kyori.examination.ExaminableProperty>
     
    final @NotNull TriState
    Checks if this translator has any translations.
    final int
     
    final @NotNull Key
    A key identifying this translation source.
    final void
    register(@NotNull String key, @NotNull Locale locale, T translation)
    Registers a translation.
    final void
    registerAll(@NotNull Locale locale, @NotNull Map<String,T> translations)
    Registers a map of translations.
    final void
    registerAll(@NotNull Locale locale, @NotNull Set<String> keys, Function<String,T> function)
    Registers translations with a set of keys and a mapping function to produce the translation from the key.
    final @NotNull String
     
    protected T
    translationValue(@NotNull String key, @NotNull Locale locale)
    Returns a translation for a given key and locale, if any.
    final void
    unregister(@NotNull String key)
    Unregisters a translation key.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface net.kyori.examination.Examinable

    examinableName, examine

    Methods inherited from interface net.kyori.adventure.translation.Translator

    translate, translate
  • Constructor Details

    • AbstractTranslationStore

      protected AbstractTranslationStore(@NotNull @NotNull Key name)
      Creates a new abstract translation store with a given name.
      Parameters:
      name - the name
      Since:
      4.20.0
  • Method Details

    • translationValue

      @Nullable protected T translationValue(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
      Returns a translation for a given key and locale, if any.
      Parameters:
      key - the key
      locale - the locale
      Returns:
      the translation, or null if none exists for this key
      Since:
      4.20.0
    • contains

      public final boolean contains(@NotNull @NotNull String key)
      Description copied from interface: TranslationStore
      Checks if any translations are explicitly registered for the specified key.
      Specified by:
      contains in interface TranslationStore<T>
      Parameters:
      key - a translation key
      Returns:
      whether the store contains a value for the translation key
    • contains

      public final boolean contains(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
      Description copied from interface: TranslationStore
      Checks if any translations are explicitly registered for the specified key and locale.

      Note that this method is different from TranslationStore.canTranslate(String, Locale) as this method does not check for translations in other locales (e.g., the default locale). This means that if a translation exists in the default locale for a given key (but not the provided locale), TranslationStore.canTranslate(String, Locale) would return true but this method would return false.

      Specified by:
      contains in interface TranslationStore<T>
      Parameters:
      key - a translation key
      locale - the locale
      Returns:
      whether the store contains a value for the translation key and locale
      See Also:
    • canTranslate

      public final boolean canTranslate(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
      Description copied from interface: TranslationStore
      Checks if this translator can translate the given key and locale pair.

      Note that this method is different from TranslationStore.contains(String, Locale) as this method checks for translations in other locales (e.g., the default locale). This means that if a translation exists in the default locale for a given key (but not the provided locale), TranslationStore.contains(String, Locale) would return false but this method would return true.

      Specified by:
      canTranslate in interface TranslationStore<T>
      Specified by:
      canTranslate in interface Translator
      Parameters:
      key - the key
      locale - the locale
      Returns:
      true if this translator will return a non-null value for either of the two translate methods
      See Also:
    • defaultLocale

      public final void defaultLocale(@NotNull @NotNull Locale locale)
      Description copied from interface: TranslationStore
      Sets the default locale used by this store.
      Specified by:
      defaultLocale in interface TranslationStore<T>
      Parameters:
      locale - the locale to use a default
    • register

      public final void register(@NotNull @NotNull String key, @NotNull @NotNull Locale locale, @NotNull T translation)
      Description copied from interface: TranslationStore
      Registers a translation.
      Specified by:
      register in interface TranslationStore<T>
      Parameters:
      key - a translation key
      locale - a locale
      translation - the translation
    • registerAll

      public final void registerAll(@NotNull @NotNull Locale locale, @NotNull @NotNull Map<String,T> translations)
      Description copied from interface: TranslationStore
      Registers a map of translations.
      Specified by:
      registerAll in interface TranslationStore<T>
      Parameters:
      locale - a locale
      translations - a map of translation keys to translations
      See Also:
    • registerAll

      public final void registerAll(@NotNull @NotNull Locale locale, @NotNull @NotNull Set<String> keys, Function<String,T> function)
      Description copied from interface: TranslationStore
      Registers translations with a set of keys and a mapping function to produce the translation from the key.
      Specified by:
      registerAll in interface TranslationStore<T>
      Parameters:
      locale - a locale
      keys - the translation keys to register
      function - a function to transform a key into a message format
    • unregister

      public final void unregister(@NotNull @NotNull String key)
      Description copied from interface: TranslationStore
      Unregisters a translation key.
      Specified by:
      unregister in interface TranslationStore<T>
      Parameters:
      key - a translation key
    • name

      @NotNull public final @NotNull Key name()
      Description copied from interface: Translator
      A key identifying this translation source.

      Intended to be used for display to users.

      Specified by:
      name in interface Translator
      Returns:
      an identifier for this translation source
    • hasAnyTranslations

      @NotNull public final @NotNull TriState hasAnyTranslations()
      Description copied from interface: Translator
      Checks if this translator has any translations.
      Specified by:
      hasAnyTranslations in interface Translator
      Returns:
      TriState.TRUE if any, TriState.NOT_SET if unknown, or TriState.FALSE if none
    • examinableProperties

      @NotNull public final @NotNull Stream<? extends net.kyori.examination.ExaminableProperty> examinableProperties()
      Specified by:
      examinableProperties in interface net.kyori.examination.Examinable
    • equals

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @NotNull public final @NotNull String toString()
      Overrides:
      toString in class Object