Skip to content

Commit

Permalink
fix: portal selector lore formatting fixed when client_side_translati…
Browse files Browse the repository at this point in the history
…ons was disabled
  • Loading branch information
oddlama committed Jun 29, 2022
1 parent 4889686 commit 1adc4f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public String key() {

public String str(Object... args) {
try {
final var list = new Object[args.length];
final var args_as_strings = new Object[args.length];
for (int i = 0; i < args.length; ++i) {
if (args[i] instanceof Component) {
list[i] = LegacyComponentSerializer.legacySection().serialize((Component) args[i]);
args_as_strings[i] = LegacyComponentSerializer.legacySection().serialize((Component) args[i]);
} else if (args[i] instanceof String) {
list[i] = args[i];
args_as_strings[i] = args[i];
} else {
throw new RuntimeException(
"Error while formatting message '" + key() + "', invalid argument to str() serializer" + args[i]
"Error while formatting message '" + key() + "', invalid argument to str() serializer: " + args[i]
);
}
}
return String.format(default_translation, list);
return String.format(default_translation, args_as_strings);
} catch (Exception e) {
throw new RuntimeException("Error while formatting message '" + key() + "'", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,22 @@ public String key() {

public List<String> str(Object... args) {
try {
final var args_as_strings = new Object[args.length];
for (int i = 0; i < args.length; ++i) {
if (args[i] instanceof Component) {
args_as_strings[i] = LegacyComponentSerializer.legacySection().serialize((Component) args[i]);
} else if (args[i] instanceof String) {
args_as_strings[i] = args[i];
} else {
throw new RuntimeException(
"Error while formatting message '" + key() + "', invalid argument to str() serializer: " + args[i]
);
}
}

final var list = new ArrayList<String>();
for (final var s : default_translation) {
list.add(String.format(s, args));
list.add(String.format(s, args_as_strings));
}
return list;
} catch (Exception e) {
Expand Down

0 comments on commit 1adc4f2

Please sign in to comment.