Class 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
- Since:
- 4.20.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An abstract, string-based translation store. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractTranslationStore
(@NotNull Key name) Creates a new abstract translation store with a given name. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
canTranslate
(@NotNull String key, @NotNull Locale locale) Checks if this translator can translate the given key and locale pair.final boolean
Checks if any translations are explicitly registered for the specified key.final boolean
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
final @NotNull Stream<? extends net.kyori.examination.ExaminableProperty>
final @NotNull TriState
Checks if this translator has any translations.final int
hashCode()
final @NotNull Key
name()
A key identifying this translation source.final void
Registers a translation.final void
registerAll
(@NotNull Locale locale, @NotNull Map<String, T> translations) Registers a map of translations.final void
Registers translations with a set of keys and a mapping function to produce the translation from the key.final @NotNull String
toString()
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
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 keylocale
- the locale- Returns:
- the translation, or
null
if none exists for this key - Since:
- 4.20.0
-
contains
Description copied from interface:TranslationStore
Checks if any translations are explicitly registered for the specified key.- Specified by:
contains
in interfaceTranslationStore<T>
- Parameters:
key
- a translation key- Returns:
- whether the store contains a value for the translation key
-
contains
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 returntrue
but this method would returnfalse
.- Specified by:
contains
in interfaceTranslationStore<T>
- Parameters:
key
- a translation keylocale
- the locale- Returns:
- whether the store contains a value for the translation key and locale
- See Also:
-
canTranslate
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 returnfalse
but this method would returntrue
.- Specified by:
canTranslate
in interfaceTranslationStore<T>
- 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- See Also:
-
defaultLocale
Description copied from interface:TranslationStore
Sets the default locale used by this store.- Specified by:
defaultLocale
in interfaceTranslationStore<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 interfaceTranslationStore<T>
- Parameters:
key
- a translation keylocale
- a localetranslation
- 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 interfaceTranslationStore<T>
- Parameters:
locale
- a localetranslations
- 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 interfaceTranslationStore<T>
- Parameters:
locale
- a localekeys
- the translation keys to registerfunction
- a function to transform a key into a message format
-
unregister
Description copied from interface:TranslationStore
Unregisters a translation key.- Specified by:
unregister
in interfaceTranslationStore<T>
- Parameters:
key
- a translation 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 interfaceTranslator
- Returns:
- an identifier for this translation source
-
hasAnyTranslations
Description copied from interface:Translator
Checks if this translator has any translations.- Specified by:
hasAnyTranslations
in interfaceTranslator
- Returns:
TriState.TRUE
if any,TriState.NOT_SET
if unknown, orTriState.FALSE
if none
-
examinableProperties
@NotNull public final @NotNull Stream<? extends net.kyori.examination.ExaminableProperty> examinableProperties()- Specified by:
examinableProperties
in interfacenet.kyori.examination.Examinable
-
equals
-
hashCode
public final int hashCode() -
toString
-