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
Direct Known Subclasses:
AbstractTranslationStore.StringBased

public abstract class AbstractTranslationStore<T> extends Object implements TranslationStore<T>
An abstraction to ease the construction of translation stores with generic values.
Since:
4.20.0
  • Constructor Details

    • AbstractTranslationStore

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

    • translationValue

      protected @Nullable T translationValue(String key, 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(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(String key, 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(String key, 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(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(String key, Locale locale, 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(Locale locale, 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(Locale locale, 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(String key)
      Description copied from interface: TranslationStore
      Unregisters a translation key.
      Specified by:
      unregister in interface TranslationStore<T>
      Parameters:
      key - a translation key
    • name

      public final 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

      public final 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
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object