1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-23 16:59:33 +00:00

Use translation strings for everything that should be translated

This commit is contained in:
Eclipse
2025-06-06 14:57:29 +00:00
parent 05f1bf2135
commit 44d229a4aa
9 changed files with 31 additions and 21 deletions

View File

@@ -165,8 +165,8 @@ public class CommandRegistry implements EventRegistrar {
registerBuiltInCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
registerBuiltInCommand(new ConnectionTestCommand(geyser, "connectiontest", "geyser.commands.connectiontest.desc", "geyser.command.connectiontest"));
registerBuiltInCommand(new PingCommand("ping", "geyser.commands.ping.desc", "geyser.command.ping"));
registerBuiltInCommand(new CustomOptionsCommand("options", "Opens the custom options dialog provided by the server, if any", "geyser.command.options"));
registerBuiltInCommand(new QuickActionsCommand("quickactions", "Opens the quick actions dialog provided by the server, if any", "geyser.command.options"));
registerBuiltInCommand(new CustomOptionsCommand("options", "geyser.commands.options.desc", "geyser.command.options"));
registerBuiltInCommand(new QuickActionsCommand("quickactions", "geyser.commands.quickactions.desc", "geyser.command.options"));
if (this.geyser.getPlatformType() == PlatformType.STANDALONE) {
registerBuiltInCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));

View File

@@ -25,7 +25,6 @@
package org.geysermc.geyser.command.defaults;
import net.kyori.adventure.text.Component;
import org.geysermc.geyser.api.util.TriState;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource;
@@ -42,7 +41,7 @@ public class CustomOptionsCommand extends GeyserCommand {
@Override
public void execute(CommandContext<GeyserCommandSource> context) {
if (!Objects.requireNonNull(context.sender().connection()).openPauseScreenAdditions()) {
context.sender().sendMessage(Component.text("The server has not provided any custom options"));
context.sender().sendMessage("geyser.commands.options.fail");
}
}
}

View File

@@ -42,7 +42,7 @@ public class QuickActionsCommand extends GeyserCommand {
@Override
public void execute(CommandContext<GeyserCommandSource> context) {
if (!Objects.requireNonNull(context.sender().connection()).openQuickActions()) {
context.sender().sendMessage(Component.text("The server has not provided any quick actions"));
context.sender().sendMessage(Component.text("geyser.commands.quickactions.fail"));
}
}
}

View File

@@ -132,7 +132,7 @@ public abstract class Dialog {
builder.label(label);
}
restored.ifPresentOrElse(last -> last.restore(builder), () -> inputs.forEach(input -> input.addComponent(builder)));
restored.ifPresentOrElse(last -> last.restore(holder, builder), () -> inputs.forEach(input -> input.addComponent(builder)));
builder.closedOrInvalidResultHandler(response -> holder.closeDialog(onCancel()));
addCustomComponents(holder, builder);
return builder;

View File

@@ -35,6 +35,7 @@ import org.geysermc.cumulus.form.SimpleForm;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.dialog.action.DialogAction;
import org.geysermc.geyser.session.dialog.input.ParsedInputs;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.text.MessageTranslator;
@@ -212,11 +213,11 @@ public class DialogHolder {
* Opens a "waiting for response" form. This method assumes the dialog is still valid!
*/
private void waitForResponse() {
String content = "Geyser is waiting for the server to respond with a new dialog.";
String content;
if (sendBackButton) {
content += " The server is taking a while to respond. You can press the button below to go back to the game.";
content = GeyserLocale.getPlayerLocaleString("geyser.dialogs.waiting_for_a_while", session.locale());
} else {
content += " If no new dialog is shown within 5 seconds, a button will appear to go back to the game.";
content = GeyserLocale.getPlayerLocaleString("geyser.dialogs.waiting_for_response", session.locale());
}
session.sendDialogForm(SimpleForm.builder()
@@ -316,14 +317,15 @@ public class DialogHolder {
*/
private void showUrl(String url) {
String content = MessageTranslator.convertMessage(session,
Component.text("The server is asking you to open the following URL:\n\n")
Component.text(GeyserLocale.getPlayerLocaleString("geyser.dialogs.open_url", session.locale()))
.append(Component.text("\n\n"))
.append(Component.text(url))
.append(Component.text("\n\n"))
.append(Component.translatable("chat.link.warning").color(NamedTextColor.RED)));
session.sendDialogForm(SimpleForm.builder()
.translator(MinecraftLocale::getLocaleString, session.locale())
.title("Open URL")
.title("chat.link.open")
.content(content)
.button("gui.ok")
.resultHandler((form, result) -> {

View File

@@ -31,6 +31,7 @@ import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.cumulus.form.SimpleForm;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.dialog.input.ParsedInputs;
import org.geysermc.geyser.text.GeyserLocale;
import java.util.List;
import java.util.Optional;
@@ -51,7 +52,7 @@ public abstract class DialogWithButtons extends Dialog {
List<DialogButton> buttons = buttons(holder);
DropdownComponent.Builder dropdown = DropdownComponent.builder();
dropdown.text("Please select an option:");
dropdown.text(GeyserLocale.getPlayerLocaleString("geyser.dialogs.select_action", holder.session().locale()));
for (DialogButton button : buttons) {
dropdown.option(button.label());
}

View File

@@ -32,9 +32,12 @@ public class DialogInputParseException extends Exception {
// Exceptions don't work with generics, so we have to do a bit of unsafe casting and assume the object is of the input type :(
@Getter
private final Object partial;
@Getter
private final Object[] values;
public DialogInputParseException(String message, Object partial) {
public DialogInputParseException(String message, Object partial, Object... values) {
super(message);
this.partial = partial;
this.values = values;
}
}

View File

@@ -29,6 +29,8 @@ import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.cumulus.response.CustomFormResponse;
import org.geysermc.geyser.session.dialog.DialogHolder;
import org.geysermc.geyser.text.GeyserLocale;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -40,7 +42,7 @@ public class ParsedInputs {
public static final ParsedInputs EMPTY = new ParsedInputs(List.of());
private final Map<DialogInput<?>, Object> values = new LinkedHashMap<>();
private final Map<DialogInput<?>, String> errors = new HashMap<>();
private final Map<DialogInput<?>, DialogInputParseException> errors = new HashMap<>();
public ParsedInputs(List<DialogInput<?>> inputs, CustomFormResponse response) {
for (DialogInput<?> input : inputs) {
@@ -48,7 +50,7 @@ public class ParsedInputs {
values.put(input, input.read(response));
} catch (DialogInputParseException exception) {
values.put(input, exception.getPartial());
errors.put(input, exception.getMessage());
errors.put(input, exception);
}
}
}
@@ -59,12 +61,15 @@ public class ParsedInputs {
}
}
public void restore(CustomForm.Builder builder) {
public void restore(DialogHolder holder, CustomForm.Builder builder) {
for (Map.Entry<DialogInput<?>, Object> entry : values.entrySet()) {
String error = errors.get(entry.getKey());
if (error != null) {
builder.label("§cError parsing input data: " + error + ".");
builder.label("§cPlease adjust!");
DialogInputParseException exception = errors.get(entry.getKey());
if (exception != null) {
String formattedException = GeyserLocale.getPlayerLocaleString(exception.getMessage(), holder.session().locale(), exception.getValues());
String error = GeyserLocale.getPlayerLocaleString("geyser.dialogs.input_validation_error", holder.session().locale(), formattedException);
builder.label("§c" + error);
builder.label("§c" + GeyserLocale.getPlayerLocaleString("geyser.dialogs.input_adjust", holder.session().locale()));
}
// Can't be a Geyser update without eclipse dealing with generics
((DialogInput) entry.getKey()).addComponent(builder, Optional.of(entry.getValue()));

View File

@@ -60,7 +60,7 @@ public class TextInput extends DialogInput<String> {
String text = response.asInput();
assert text != null;
if (text.length() > maxLength) {
throw new DialogInputParseException("length of text cannot be above " + maxLength, text);
throw new DialogInputParseException("geyser.dialogs.text_input_limit", text, maxLength);
}
return text;
}