Interface TranslationStore<T>
- Type Parameters:
T
- the type of the values.
- All Superinterfaces:
Translator
- All Known Subinterfaces:
TranslationRegistry
,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 interface
An abstract, string-based translation store. -
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
canTranslate
(@NotNull String key, @NotNull Locale locale) Checks if this translator can translate the given key and locale pair.static @NotNull TranslationStore<Component>
Creates a new translation store that uses component-based translation.boolean
Checks if any translations are explicitly registered for the specified key.boolean
Checks if any translations are explicitly registered for the specified key and locale.void
defaultLocale
(@NotNull Locale locale) Sets the default locale used by this store.static @NotNull TranslationStore.StringBased<MessageFormat>
messageFormat
(@NotNull Key name) Creates a new translation store that uses message-format-based translation.void
Registers a translation.void
registerAll
(@NotNull Locale locale, @NotNull Map<String, T> translations) Registers a map of translations.void
Registers translations with a set of keys and a mapping function to produce the translation from the key.void
unregister
(@NotNull String key) Unregisters a translation key.Methods inherited from interface net.kyori.adventure.translation.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
static @NotNull TranslationStore.StringBased<MessageFormat> messageFormat(@NotNull @NotNull 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
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 returntrue
but 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 returnfalse
but this method would returntrue
.- Specified by:
canTranslate
in interfaceTranslator
- Parameters:
key
- the keylocale
- the locale- Returns:
true
if this translator will return a non-null value for either of the twotranslate
methods- 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
void registerAll(@NotNull @NotNull Locale locale, @NotNull @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.- 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
-