The bug
The strings at position and [HERE] of the immediate command response cannot be translated.
How to reproduce
Switch to any non English language
Type
/experience set @a test
Remark
The [HERE]
of the command echo is translatable
Analysis
Code analysis of this issue can be found in this comment by @unknown.
Attachments
Comments 21
Like I said, we all can translate string command.context.here, but it isn't translated in command input... see attached image. It is only translated as chat message, but no in command input.
make sure the translations actually translate it/got updated to translate it (you can check this by overwriting the en_us language file to say something else).
But first string isn't translatable and it should be... it isn't from JSON, why it should be from JSON, when it is only string like other? He probably thought some special strings.
And about [HERE], it only translate message in chat, no in command input and it probably also should. We translated it a week ago and in new pre-release it is also [HERE] but in chat we have [ZDE], so in chat it works.
The string "at position" is translated but the string "[HERE]" is not translated in 1.16.4 Release Candidate 1
The "at position" message is translatable now (command.context.parse_error), but "<--[HERE]" is still hardcoded when typing a command. See attached screenshot, it is translated in chat but not in the command suggestion area.
[media]
I've dug into the Minecraft code (version 1.17.1-pre1, decompiled using Mojang's mappings) and found the cause. I've come up with a possible fix, but I'm not entirely sure it will work, as I've had no way to test it and my Java knowledge is extremely limited and extremely rusty.
Code analysis
com.mojang.brigadier.exceptions.CommandSyntaxtExceptions.java
The getContext
method returns the last 10 characters of a faulty inputted command, followed by "<--[HERE]-
". "<-[HERE]-
" is defined directly in the code, so it's not translatable. This is intended, Brigadier is meant to be a standalone library which can be used by other pieces of software, so it should not directly reference any Minecraft classes or assets. However, this is the reason why "<-[HERE]
" is not translatable in the parse error message.
public String getContext() {
if (this.input == null || this.cursor < 0) {
return null;
}
StringBuilder stringBuilder = new StringBuilder();
int n = Math.min(this.input.length(), this.cursor);
if (n > 10) {
stringBuilder.append("...");
}
stringBuilder.append(this.input.substring(Math.max(0, n - 10), n));
stringBuilder.append("<--[HERE]");
return stringBuilder.toString();
}
net.minecraft.client.gui.components.CommandSuggestions.java
The getExceptionMessage
method prepares the parse error message by inputting the cursor position and the command context in the translation string command.context.parse_error
("in position %s: %s"). The command context is returned by the getContext
method from the Brigadier library, so it includes the hardcoded "<--[HERE]
".
private static FormattedCharSequence getExceptionMessage(CommandSyntaxException commandSyntaxException) {
Component component = ComponentUtils.fromMessage(commandSyntaxException.getRawMessage());
String string = commandSyntaxException.getContext();
if (string == null) {
return component.getVisualOrderText();
}
return new TranslatableComponent("command.context.parse_error", component, commandSyntaxException.getCursor(), string).getVisualOrderText();
}
Possible fix
com.mojang.brigadier.exceptions.CommandSyntaxtExceptions.java
I suggest fixing it by adding a new method which only returns the last 10 characters of the input command, whithout appending anything after it. The game will use this method - instead of getContext
- to prepare the parse error message.
public String getRawContext() {
if (this.input == null || this.cursor < 0) {
return null;
}
StringBuilder stringBuilder = new StringBuilder();
int n = Math.min(this.input.length(), this.cursor);
if (n > 10) {
stringBuilder.append("...");
}
stringBuilder.append(this.input.substring(Math.max(0, n - 10), n));
return stringBuilder.toString();
}
getContext
now will simply append "<--[HERE]
" to the output of getRawContext
.
public String getContext() {
StringBuilder stringBuilder = newStringBuilder(this.getRawContext());
stringBuilder.append("<--[HERE]");
return stringBuilder.toString()
}
net.minecraft.client.gui.components.CommandSuggestions.java
getExceptionMessage
will now reference getRawContext
instead of getContext
.
private static FormattedCharSequence getExceptionMessage(CommandSyntaxException commandSyntaxException) {
Component component = ComponentUtils.fromMessage(commandSyntaxException.getRawMessage());
String string = commandSyntaxException.getRawContext();
if (string == null) {
return component.getVisualOrderText();
}
return new TranslatableComponent("command.context.parse_error", component, commandSyntaxException.getCursor(), string).getVisualOrderText();
}
en_us.json
The string command.context.parse_error
should then be changed to include "<--[HERE]
", allowing translators to translate it properly and change the word order if needed.
"command.context.parse_error": "in position %s: %s<--[HERE]",
This is a translation error, as you said.
Only the managers of the project can add/remove new strings to translate. However, the string "[HERE]" is translatable ( https://gyazo.com/9c1eafb4485b9bea72614d2a43feca87 ). Probably the string "[HERE]" is NOT translated in your language (if one string is not translated, it will be replaced with the default string in English).
Could you tell me what language is that, please? Or you can translate it here.
Thanks for your report.