args.add(this.deserialize(argElement, argElement.getClass(), context)); component = TranslatableComponent.builder(key).args(args);
args.add(this.deserialize(argElement, argElement.getClass(), context)); component = TranslatableComponent.builder(key).args(args);
/** * Sets the translation args. * * @param args the translation args * @return this builder */ public @NonNull Builder args(final @NonNull Component... args) { return this.args(Arrays.asList(args)); }
.builder() .key("cats") .args( TextComponent.of("kashike"), TextComponent.of("lucko")
@Test void testComplex() { final FriendlyComponentRenderer<ComponentRenderer.Context> renderer = FriendlyComponentRenderer.from((locale, key) -> new MessageFormat(TRANSLATIONS.get(locale, key), locale)); assertEquals( TextComponent.builder("") .color(TextColor.YELLOW) .append(TextComponent.of("kashike")) .append(TextComponent.of(" and ")) .append(TextComponent.of("lucko")) .append(TextComponent.of(" are cats.")) .build(), renderer.render( TranslatableComponent .builder() .key("cats") .args( TextComponent.of("kashike"), TextComponent.of("lucko") ) .color(TextColor.YELLOW) .build(), new ComponentRenderer.Context() { @Override public @NonNull Locale locale() { return Locale.US; } } ) ); }
/** * Creates a translatable component with a translation key and arguments. * * @param key the translation key * @param color the color * @param decorations the decorations * @param args the translation arguments * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations, final @NonNull List<Component> args) { return builder() .color(color) .decorations(decorations, true) .key(key) .args(args) .build(); }
/** * Creates a translatable component with a translation key and arguments. * * @param key the translation key * @param color the color * @param decorations the decorations * @param args the translation arguments * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations, final @NonNull List<Component> args) { return builder() .color(color) .decorations(decorations, true) .key(key) .args(args) .build(); }
/** * Creates a translatable component with a translation key and arguments. * * @param key the translation key * @param color the color * @param decorations the decorations * @param args the translation arguments * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations, final @NonNull List<Component> args) { return builder() .color(color) .decorations(decorations, true) .key(key) .args(args) .build(); }
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param key the translation key * @param args the translation arguments * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull String key, final @NonNull List<Component> args, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(key).args(args); consumer.accept(builder); return builder.build(); }
/** * Sets the translation args. * * @param args the translation args * @return this builder */ public @NonNull Builder args(final @NonNull Component... args) { return this.args(Arrays.asList(args)); }
@Test void testDeserializeTranslatable() { assertEquals(TranslatableComponent.of("multiplayer.player.left"), GsonComponentSerializer.INSTANCE.deserialize("{\"translate\":\"multiplayer.player.left\"}")); assertEquals(TranslatableComponent.builder("multiplayer.player.left") .args(TextComponent.of("kashike")) .build(), GsonComponentSerializer.INSTANCE.deserialize("{\"translate\":\"multiplayer.player.left\",\"with\":[{\"text\":\"kashike\"}]}")); }
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param key the translation key * @param args the translation arguments * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull String key, final @NonNull List<Component> args, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(key).args(args); consumer.accept(builder); return builder.build(); }
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param key the translation key * @param args the translation arguments * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull String key, final @NonNull List<Component> args, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(key).args(args); consumer.accept(builder); return builder.build(); }
/** * Sets the translation args. * * @param args the translation args * @return this builder */ public @NonNull Builder args(final @NonNull Component... args) { return this.args(Arrays.asList(args)); }