Interface TranslatableComponent
- All Superinterfaces:
Buildable<TranslatableComponent,TranslatableComponent.Builder>
,BuildableComponent<TranslatableComponent,TranslatableComponent.Builder>
,Component
,ComponentBuilderApplicable
,ComponentLike
,net.kyori.examination.Examinable
,HoverEventSource<Component>
,ScopedComponent<TranslatableComponent>
public interface TranslatableComponent extends BuildableComponent<TranslatableComponent,TranslatableComponent.Builder>, ScopedComponent<TranslatableComponent>
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:
GlobalTranslator
,TranslationRegistry
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
TranslatableComponent.Builder
A text component builder. -
Method Summary
Modifier and Type Method Description @NonNull List<Component>
args()
Gets the unmodifiable list of translation arguments.@NonNull TranslatableComponent
args(@NonNull List<? extends ComponentLike> args)
Sets the translation arguments for this component.@NonNull TranslatableComponent
args(@NonNull ComponentLike @NonNull ... args)
Sets the translation arguments for this component.@NonNull String
key()
Gets the translation key.@NonNull TranslatableComponent
key(@NonNull String key)
Sets the translation key.Methods inherited from interface net.kyori.adventure.text.BuildableComponent
toBuilder
Methods inherited from interface net.kyori.adventure.text.Component
asComponent, asHoverEvent, children, clickEvent, color, componentBuilderApply, contains, decoration, decorations, decorations, detectCycle, hasDecoration, hasStyling, hoverEvent, insertion, replaceFirstText, replaceFirstText, replaceText, replaceText, replaceText, replaceText, replaceText, replaceText, replaceText, replaceText, style, style
Methods inherited from interface net.kyori.examination.Examinable
examinableName, examinableProperties, examine
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
-
Method Details
-
key
@NonNull String key()Gets the translation key.- Returns:
- the translation key
- Since:
- 4.0.0
-
key
Sets the translation key.- Parameters:
key
- the translation key- Returns:
- a translatable component
- Since:
- 4.0.0
-
args
Gets the unmodifiable list of translation arguments.- Returns:
- the unmodifiable list of translation arguments
- Since:
- 4.0.0
-
args
Sets the translation arguments for this component.- Parameters:
args
- the translation arguments- Returns:
- a translatable component
- Since:
- 4.0.0
-
args
@Contract(pure=true) @NonNull TranslatableComponent args(@NonNull List<? extends ComponentLike> args)Sets the translation arguments for this component.- Parameters:
args
- the translation arguments- Returns:
- a translatable component
- Since:
- 4.0.0
-