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
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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn abstract, string-based translation store. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanTranslate(String key, Locale locale) Checks if this translator can translate the given key and locale pair.static TranslationStore<Component> Creates a new translation store that uses component-based translation.booleanChecks if any translations are explicitly registered for the specified key.booleanChecks if any translations are explicitly registered for the specified key and locale.voiddefaultLocale(Locale locale) Sets the default locale used by this store.messageFormat(Key name) Creates a new translation store that uses message-format-based translation.voidRegisters a translation.voidregisterAll(Locale locale, Map<String, T> translations) Registers a map of translations.voidRegisters translations with a set of keys and a mapping function to produce the translation from the key.voidunregister(String key) Unregisters a translation key.Methods inherited from interface Translator
hasAnyTranslations, name, translate, translate
-
Method Details
-
component
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
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
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
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 returntruebut this method would returnfalse.- Parameters:
key- a translation keylocale- the locale- Returns:
- whether the store contains a value for the translation key and locale
- Since:
- 4.20.0
- See Also:
-
canTranslate
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 returnfalsebut this method would returntrue.- Specified by:
canTranslatein interfaceTranslator- Parameters:
key- the keylocale- the locale- Returns:
trueif this translator will return a non-null value for either of the twotranslatemethods- Since:
- 4.20.0
- See Also:
-
defaultLocale
Sets the default locale used by this store.- Parameters:
locale- the locale to use a default- Since:
- 4.20.0
-
register
Registers a translation.- Parameters:
key- a translation keylocale- a localetranslation- the translation- Throws:
IllegalArgumentException- if the translation key already exists- Since:
- 4.20.0
-
registerAll
Registers a map of translations.- Parameters:
locale- a localetranslations- a map of translation keys to translations- Throws:
IllegalArgumentException- if a translation key already exists- Since:
- 4.20.0
- See Also:
-
registerAll
Registers translations with a set of keys and a mapping function to produce the translation from the key.- Parameters:
locale- a localekeys- the translation keys to registerfunction- a function to transform a key into a message format- Throws:
IllegalArgumentException- if a translation key already exists- Since:
- 4.20.0
-
unregister
Unregisters a translation key.- Parameters:
key- a translation key- Since:
- 4.0.0
-