@Test void testSimple() { final FriendlyComponentRenderer<ComponentRenderer.Context> renderer = FriendlyComponentRenderer.from((locale, key) -> new MessageFormat(TRANSLATIONS.get(locale, key), locale)); assertEquals( TextComponent.builder("This is a test.") .color(TextColor.YELLOW) .build(), renderer.render( TranslatableComponent .builder() .key("test") .color(TextColor.YELLOW) .build(), new ComponentRenderer.Context() { @Override public @NonNull Locale locale() { return Locale.US; } } ) ); }
@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 with a translation key. * * @param key the translation key * @param color the color * @param decorations the decorations * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(key) .color(color) .decorations(decorations, true) .build(); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @param decorations the decorations * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(key) .color(color) .decorations(decorations, true) .build(); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @param decorations the decorations * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(key) .color(color) .decorations(decorations, true) .build(); }
@Test void testMake_content() { final TranslatableComponent component = TranslatableComponent.make("multiplayer.player.left", builder -> builder.color(TextColor.DARK_PURPLE)); assertEquals("multiplayer.player.left", component.key()); assertEquals(TextColor.DARK_PURPLE, component.color()); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color) { return builder(key) .color(color) .build(); }
@Test void testMake() { final TranslatableComponent component = TranslatableComponent.make(builder -> { builder.key("multiplayer.player.left"); builder.color(TextColor.DARK_PURPLE); }); assertEquals("multiplayer.player.left", component.key()); assertEquals(TextColor.DARK_PURPLE, component.color()); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color) { return builder(key) .color(color) .build(); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color) { return builder(key) .color(color) .build(); }