Interface TranslatableComponent
-
- All Superinterfaces:
Buildable<TranslatableComponent,TranslatableComponent.Builder>
,BuildableComponent<TranslatableComponent,TranslatableComponent.Builder>
,Component
,ComponentBuilderApplicable
,ComponentLike
,net.kyori.examination.Examinable
,HoverEventSource<Component>
,ScopedComponent<TranslatableComponent>
,StyleGetter
,StyleSetter<Component>
public interface TranslatableComponent extends BuildableComponent<TranslatableComponent,TranslatableComponent.Builder>, ScopedComponent<TranslatableComponent>
A component that can display translated text.This component consists of:
- key
- a translation key used together with the viewer locale to fetch a translated string.
- args(optional)
- components that can be used as arguments in the translated string.
(e.g "You picked up {0}." -> "You picked up Carrot.")
Displaying this component through an
Audience
will run it through theGlobalTranslator
by default, rendering the key as translated text if a translation with a key matching this components key is found in the viewers locale, optionally switching arguments with any placeholders in the discovered translation. If no translation is registered for the viewers locale adventure will first try to find similar locales that has a valid translation, and then find a translation in the default language(relevant method
).In addition to the initial attempts, if no translation is found in the serverside registry, the translation key and arguments will be passed through to the client which will perform translation using any keys defined in an active resource pack. (Hint: vanilla Minecraft is also considered a resource pack)
- Since:
- 4.0.0
- See Also:
GlobalTranslator
,TranslationRegistry
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
TranslatableComponent.Builder
A text component builder.
-
Field Summary
-
Fields inherited from interface net.kyori.adventure.text.Component
EQUALS, EQUALS_IDENTITY, IS_NOT_EMPTY
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description @NotNull java.util.List<Component>
args()
Deprecated.for removal since 4.15.0, usearguments()
instead.default @NotNull TranslatableComponent
args(@NotNull java.util.List<? extends ComponentLike> args)
Deprecated.for removal since 4.15.0, usearguments(List)
insteaddefault @NotNull TranslatableComponent
args(@NotNull ComponentLike @NotNull ... args)
Deprecated.for removal since 4.15.0, usearguments(ComponentLike...)
instead@NotNull java.util.List<TranslationArgument>
arguments()
Gets the unmodifiable list of translation arguments.@NotNull TranslatableComponent
arguments(@NotNull java.util.List<? extends ComponentLike> args)
Sets the translation arguments for this component.@NotNull TranslatableComponent
arguments(@NotNull ComponentLike @NotNull ... args)
Sets the translation arguments for this component.default @NotNull java.util.stream.Stream<? extends net.kyori.examination.ExaminableProperty>
examinableProperties()
@Nullable java.lang.String
fallback()
Gets the translation fallback text for this component.@NotNull TranslatableComponent
fallback(@Nullable java.lang.String fallback)
Sets the translation fallback text for this component.@NotNull java.lang.String
key()
Gets the translation key.@NotNull TranslatableComponent
key(@NotNull java.lang.String key)
Sets the translation key.default @NotNull TranslatableComponent
key(@NotNull Translatable translatable)
Sets the translation key.-
Methods inherited from interface net.kyori.adventure.text.BuildableComponent
toBuilder
-
Methods inherited from interface net.kyori.adventure.text.Component
appendNewline, appendSpace, applyFallbackStyle, applyFallbackStyle, asComponent, asHoverEvent, children, clickEvent, color, compact, componentBuilderApply, contains, contains, decoration, decorationIfAbsent, decorations, decorations, detectCycle, font, font, hasDecoration, hasStyling, hoverEvent, insertion, iterable, iterable, iterator, iterator, replaceFirstText, replaceFirstText, replaceText, replaceText, replaceText, replaceText, replaceText, replaceText, replaceText, replaceText, spliterator, spliterator, style, style
-
Methods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEvent
-
Methods inherited from interface net.kyori.adventure.text.ScopedComponent
append, append, append, children, clickEvent, color, colorIfAbsent, decorate, decoration, decoration, hoverEvent, insertion, mergeStyle, mergeStyle, mergeStyle, style, style, style
-
Methods inherited from interface net.kyori.adventure.text.format.StyleSetter
decorate, decorations
-
-
-
-
Method Detail
-
key
@NotNull @NotNull java.lang.String key()
Gets the translation key.- Returns:
- the translation key
- Since:
- 4.0.0
-
key
@Contract(pure=true) @NotNull default @NotNull TranslatableComponent key(@NotNull @NotNull Translatable translatable)
Sets the translation key.- Parameters:
translatable
- the translatable object to get the key from- Returns:
- a translatable component
- Since:
- 4.8.0
-
key
@Contract(pure=true) @NotNull @NotNull TranslatableComponent key(@NotNull @NotNull java.lang.String key)
Sets the translation key.- Parameters:
key
- the translation key- Returns:
- a translatable component
- Since:
- 4.0.0
-
args
@Deprecated @NotNull @NotNull java.util.List<Component> args()
Deprecated.for removal since 4.15.0, usearguments()
instead.Gets the unmodifiable list of translation arguments.- Returns:
- the unmodifiable list of translation arguments
- Since:
- 4.0.0
-
args
@Deprecated @Contract(pure=true) @NotNull default @NotNull TranslatableComponent args(@NotNull @NotNull ComponentLike @NotNull ... args)
Deprecated.for removal since 4.15.0, usearguments(ComponentLike...)
insteadSets the translation arguments for this component.Non-
Component
arguments can be wrapped inTranslationArgument
, or represented with aTranslationArgumentLike
.- Parameters:
args
- the translation arguments- Returns:
- a translatable component
- Since:
- 4.0.0
- See Also:
TranslationArgument
-
args
@Deprecated @Contract(pure=true) @NotNull default @NotNull TranslatableComponent args(@NotNull @NotNull java.util.List<? extends ComponentLike> args)
Deprecated.for removal since 4.15.0, usearguments(List)
insteadSets the translation arguments for this component.Non-
Component
arguments can be wrapped inTranslationArgument
, or represented with aTranslationArgumentLike
.- Parameters:
args
- the translation arguments- Returns:
- a translatable component
- Since:
- 4.0.0
-
arguments
@NotNull @NotNull java.util.List<TranslationArgument> arguments()
Gets the unmodifiable list of translation arguments.- Returns:
- the unmodifiable list of translation arguments
- Since:
- 4.0.0
-
arguments
@Contract(pure=true) @NotNull @NotNull TranslatableComponent arguments(@NotNull @NotNull ComponentLike @NotNull ... args)
Sets the translation arguments for this component.Non-
Component
arguments can be wrapped inTranslationArgument
, or represented with aTranslationArgumentLike
.- Parameters:
args
- the translation arguments- Returns:
- a translatable component
- Since:
- 4.15.0
- See Also:
TranslationArgument
-
arguments
@Contract(pure=true) @NotNull @NotNull TranslatableComponent arguments(@NotNull @NotNull java.util.List<? extends ComponentLike> args)
Sets the translation arguments for this component.Non-
Component
arguments can be wrapped inTranslationArgument
, or represented with aTranslationArgumentLike
.- Parameters:
args
- the translation arguments- Returns:
- a translatable component
- Since:
- 4.15.0
-
fallback
@Nullable @Nullable java.lang.String fallback()
Gets the translation fallback text for this component. The fallback text will be shown when the client doesn't know the translation key used in the translatable component.- Returns:
- the fallback string
- Since:
- 4.13.0
- Since Minecraft:
- 1.19.4
-
fallback
@Contract(pure=true) @NotNull @NotNull TranslatableComponent fallback(@Nullable @Nullable java.lang.String fallback)
Sets the translation fallback text for this component. The fallback text will be shown when the client doesn't know the translation key used in the translatable component.- Parameters:
fallback
- the fallback string- Returns:
- a translatable component
- Since:
- 4.13.0
- Since Minecraft:
- 1.19.4
-
examinableProperties
@NotNull default @NotNull java.util.stream.Stream<? extends net.kyori.examination.ExaminableProperty> examinableProperties()
- Specified by:
examinableProperties
in interfaceComponent
- Specified by:
examinableProperties
in interfacenet.kyori.examination.Examinable
-
-