Interface TranslationStore<T>

Type Parameters:
T - the type of the values.
All Superinterfaces:
Translator
All Known Subinterfaces:
MiniMessageTranslationStore, TranslationStore.StringBased<T>
All Known Implementing Classes:
AbstractTranslationStore, AbstractTranslationStore.StringBased

public interface TranslationStore<T> extends Translator
A store of translation values.

Adventure provides two types of translation store for both component and message format translators.

If you wish to implement your own translation store, see AbstractTranslationStore for a helpful abstraction.

Since:
4.20.0
  • Method Details

    • component

      static TranslationStore<Component> component(Key name)
      Creates a new translation store that uses component-based translation.
      Parameters:
      name - the name of the translation store
      Returns:
      the translation store
      Since:
      4.20.0
    • messageFormat

      static TranslationStore.StringBased<MessageFormat> messageFormat(Key name)
      Creates a new translation store that uses message-format-based translation.
      Parameters:
      name - the name of the translation store
      Returns:
      the translation store
      Since:
      4.20.0
    • contains

      boolean contains(String key)
      Checks if any translations are explicitly registered for the specified key.
      Parameters:
      key - a translation key
      Returns:
      whether the store contains a value for the translation key
      Since:
      4.20.0
    • contains

      boolean contains(String key, Locale locale)
      Checks if any translations are explicitly registered for the specified key and locale.

      Note that this method is different from 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), canTranslate(String, Locale) would return true but this method would return false.

      Parameters:
      key - a translation key
      locale - the locale
      Returns:
      whether the store contains a value for the translation key and locale
      Since:
      4.20.0
      See Also:
    • canTranslate

      default boolean canTranslate(String key, Locale locale)
      Checks if this translator can translate the given key and locale pair.

      Note that this method is different from 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), contains(String, Locale) would return false but this method would return true.

      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
      Since:
      4.20.0
      See Also:
    • defaultLocale

      void defaultLocale(Locale locale)
      Sets the default locale used by this store.
      Parameters:
      locale - the locale to use a default
      Since:
      4.20.0
    • register

      void register(String key, Locale locale, T translation)
      Registers a translation.
      Parameters:
      key - a translation key
      locale - a locale
      translation - the translation
      Throws:
      IllegalArgumentException - if the translation key already exists
      Since:
      4.20.0
    • registerAll

      void registerAll(Locale locale, Map<String,T> translations)
      Registers a map of translations.
      Parameters:
      locale - a locale
      translations - a map of translation keys to translations
      Throws:
      IllegalArgumentException - if a translation key already exists
      Since:
      4.20.0
      See Also:
    • registerAll

      void registerAll(Locale locale, 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.
      Parameters:
      locale - a locale
      keys - the translation keys to register
      function - a function to transform a key into a message format
      Throws:
      IllegalArgumentException - if a translation key already exists
      Since:
      4.20.0
    • unregister

      void unregister(String key)
      Unregisters a translation key.
      Parameters:
      key - a translation key
      Since:
      4.0.0