Skip to content

Commit

Permalink
feat: add i18n support for other files
Browse files Browse the repository at this point in the history
  • Loading branch information
wafarm committed Sep 5, 2023
1 parent c785200 commit 79d61d1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/github/zly2006/reden/access/PlayerData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ class PlayerData(
val cause: Cause = Cause.UNKNOWN
) : UndoRedoRecord(id, lastChangedTick, entities, data) {
enum class Cause(message: Text? = null) {
BREAK_BLOCK(Text.of("Break Block")),
USE_BLOCK(Text.of("Use Block")),
USE_ITEM(Text.of("Use Item")),
ATTACK_ENTITY(Text.of("Attack Entity")),
COMMAND(Text.of("Command")),
LITEMATICA_TASK(Text.of("Litematica Task")),
UNKNOWN(Text.of("Unknown"));
BREAK_BLOCK(Text.translatable("reden.feature.undo.break_block")),
USE_BLOCK(Text.translatable("reden.feature.undo.use_block")),
USE_ITEM(Text.translatable("reden.feature.undo.use_item")),
ATTACK_ENTITY(Text.translatable("reden.feature.undo.attack_entity")),
COMMAND(Text.translatable("reden.feature.undo.command")),
LITEMATICA_TASK(Text.translatable("reden.feature.undo.litematica_task")),
UNKNOWN(Text.translatable("reden.feature.undo.unknown"));

val message: Text = message ?: Text.translatable("reden.undo.cause.${name.lowercase()}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.github.zly2006.reden.malilib.MalilibSettingsKt.*;
import static com.github.zly2006.reden.malilib.MalilibSettingsKt.CHAT_RIGHT_CLICK_MENU;

@Mixin(ChatScreen.class)
public abstract class ChatScreenMixin extends Screen {
@Unique QuickMenuWidget quickMenuWidget;
private static final Pattern urlPattern = Pattern.compile("(https?://)?[a-zA-Z0-9\\-.]+\\.[a-zA-Z]{2,8}(/\\S*)?");
@Unique QuickMenuWidget quickMenuWidget;

protected ChatScreenMixin(Text title) {
super(title);
Expand Down Expand Up @@ -79,7 +79,7 @@ private void rightClickMenu(int mouseX, int mouseY, MinecraftClient client, Text
quickMenuWidget.remove();
}
quickMenuWidget = new QuickMenuWidget(this, mouseX, mouseY);
quickMenuWidget.addEntry(Text.of("About SuperRight Chat"), (e, b) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.about"), (e, b) -> {
client.setScreen(new SuperRightIntro());
});
String message = text.getString();
Expand All @@ -91,31 +91,31 @@ private void rightClickMenu(int mouseX, int mouseY, MinecraftClient client, Text
url = "http://" + url;
}
String finalUrl = url;
quickMenuWidget.addEntry(Text.literal("Copy URL"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy_url"), (entry, button) -> {
client.keyboard.setClipboard(finalUrl);
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
}
quickMenuWidget.addEntry(Text.literal("Copy Raw"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy_raw"), (entry, button) -> {
client.keyboard.setClipboard(Text.Serializer.toJson(text));
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
quickMenuWidget.addEntry(Text.literal("Copy"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy"), (entry, button) -> {
client.keyboard.setClipboard(message);
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
if (style != null) {
if (style.getHoverEvent() != null) {
HoverEvent.Action<?> action = style.getHoverEvent().getAction();
if (action == HoverEvent.Action.SHOW_TEXT) {
quickMenuWidget.addEntry(Text.literal("Copy Hover Raw"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy_hover_raw"), (entry, button) -> {
Text hoverText = style.getHoverEvent().getValue(HoverEvent.Action.SHOW_TEXT);
client.keyboard.setClipboard(Text.Serializer.toJson(hoverText));
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
}
if (action == HoverEvent.Action.SHOW_ITEM) {
quickMenuWidget.addEntry(Text.literal("Give Hover Item"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.give_hover_item"), (entry, button) -> {
ItemStack stack = style.getHoverEvent().getValue(HoverEvent.Action.SHOW_ITEM).asStack();
if (stack.getNbt() == null) {
client.getNetworkHandler().sendChatCommand(
Expand All @@ -126,30 +126,30 @@ private void rightClickMenu(int mouseX, int mouseY, MinecraftClient client, Text
"give @s " + Registries.ITEM.getId(stack.getItem()) + stack.getNbt().toString()
);
}
entry.setName(Text.literal("Done"));
entry.setName(Text.translatable("reden.widget.chat.done"));
});
}
if (action == HoverEvent.Action.SHOW_ENTITY) {
quickMenuWidget.addEntry(Text.literal("Copy Hover UUID"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy_hover_uuid"), (entry, button) -> {
UUID uuid = style.getHoverEvent().getValue(HoverEvent.Action.SHOW_ENTITY).uuid;
client.keyboard.setClipboard(uuid.toString());
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
}
}
if (style.getClickEvent() != null) {
if (style.getClickEvent().getAction() == ClickEvent.Action.RUN_COMMAND) {
quickMenuWidget.addEntry(Text.literal("Copy Click Command"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy_click_command"), (entry, button) -> {
String command = style.getClickEvent().getValue();
client.keyboard.setClipboard(command);
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
}
if (style.getClickEvent().getAction() == ClickEvent.Action.OPEN_FILE) {
quickMenuWidget.addEntry(Text.literal("Copy Click File"), (entry, button) -> {
quickMenuWidget.addEntry(Text.translatable("reden.widget.chat.copy_click_file"), (entry, button) -> {
String file = style.getClickEvent().getValue();
client.keyboard.setClipboard(file);
entry.setName(Text.literal("Copied"));
entry.setName(Text.translatable("reden.widget.chat.copied"));
});
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/assets/reden/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ reden:
title:
commandHotkeyListEdit: Edit command list

chat:
about: About SuperRight Chat
copy: Copy
copy_click_command: Copy Click Command
copy_click_file: Copy Click File
copy_hover_raw: Copy Hover Raw
copy_hover_uuid: Copy Hover UUID
copy_raw: Copy Raw
copy_url: Copy URL
give_hover_item: Give Hover Item
copied: Copied
done: Done

feature:
undo:
break_block: Break Block
use_block: Use Block
use_item: Use Item
attack_entity: Attack Entity
command: Command
litematica_task: Litematica Task
unknown: Unknown

message:
undo:
base: "[Reden/Undo] %s"
Expand Down

0 comments on commit 79d61d1

Please sign in to comment.