Interface TranslatableComponent
- All Superinterfaces:
Component, ComponentBuilderApplicable, ComponentLike, HoverEventSource<Component>, ScopedComponent<TranslatableComponent>, StyleGetter, StyleSetter<Component>
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 the GlobalTranslator 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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA text component builder. -
Field Summary
Fields inherited from interface Component
EQUALS, EQUALS_IDENTITY, IS_NOT_EMPTY -
Method Summary
Modifier and TypeMethodDescriptionGets the unmodifiable list of translation arguments.arguments(List<? extends ComponentLike> args) Sets the translation arguments for this component.arguments(ComponentLike... args) Sets the translation arguments for this component.@Nullable Stringfallback()Gets the translation fallback text for this component.Sets the translation fallback text for this component.key()Gets the translation key.Sets the translation key.default TranslatableComponentkey(Translatable translatable) Sets the translation key.Returns a builder for this component.Methods inherited from interface Component
asHoverEvent, children, clickEvent, color, compact, compact, componentBuilderApply, contains, contains, decoration, decorations, font, hasDecoration, hasStyling, hoverEvent, insertion, iterable, iterable, iterator, iterator, replaceText, replaceText, shadowColor, spliterator, spliterator, styleMethods inherited from interface HoverEventSource
asHoverEventMethods inherited from interface ScopedComponent
append, append, append, append, append, appendNewline, appendSpace, applyFallbackStyle, applyFallbackStyle, asComponent, children, clickEvent, color, colorIfAbsent, decorate, decoration, decoration, decorationIfAbsent, decorations, font, hoverEvent, insertion, mergeStyle, mergeStyle, mergeStyle, shadowColor, shadowColorIfAbsent, style, style, style, styleMethods inherited from interface StyleSetter
decorate, decorations
-
Method Details
-
key
-
key
Sets the translation key.- Parameters:
translatable- the translatable object to get the key from- Returns:
- a translatable component
- Since:
- 4.8.0
-
key
Sets the translation key.- Parameters:
key- the translation key- Returns:
- a translatable component
- Since:
- 4.0.0
-
arguments
List<TranslationArgument> arguments()Gets the unmodifiable list of translation arguments.- Returns:
- the unmodifiable list of translation arguments
- Since:
- 4.0.0
-
arguments
Sets the translation arguments for this component.Non-
Componentarguments can be wrapped inTranslationArgument, or represented with aTranslationArgumentLike.- Parameters:
args- the translation arguments- Returns:
- a translatable component
- Since:
- 4.15.0
- See Also:
-
arguments
Sets the translation arguments for this component.Non-
Componentarguments can be wrapped inTranslationArgument, or represented with aTranslationArgumentLike.- Parameters:
args- the translation arguments- Returns:
- a translatable component
- Since:
- 4.15.0
-
fallback
@Nullable 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
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
-
toBuilder
TranslatableComponent.Builder toBuilder()Description copied from interface:ComponentReturns a builder for this component.- Specified by:
toBuilderin interfaceComponent- Specified by:
toBuilderin interfaceScopedComponent<TranslatableComponent>- Returns:
- the builder
-