Add workaround for pairs of ' being stripped (#8050)

Fixes #7396, where if a translated string with balanced pairs of single
quote characters passes through ForgeI18n, the quotes are stripped
because of ExtendedMessageFormat. This is most notable in languages
where `'` is used frequently, like Canadian French from the bug report.

Note that unbalanced pairs cause an IllegalArgumentException in
ExtendedMessageFormat, which means the message is not affected.
This commit is contained in:
sciwhiz12 authored and GitHub committed 2021-09-08 11:36:00 -07:00
1 parent 049ed79e7b
commit 9d7f5dd32a
1 file changed
+13 -1
@@ -28,7 +28,19 @@ import java.util.List;
public class TextComponentMessageFormatHandler {
public static int handle(final TranslatableComponent parent, final List<FormattedText> children, final Object[] formatArgs, final String format) {
try {
TextComponent component = new TextComponent(ForgeI18n.parseFormat(format, formatArgs));
final String formattedString = ForgeI18n.parseFormat(format, formatArgs);
// See MinecraftForge/MinecraftForge#7396
if (format.indexOf('\'') != -1) {
final boolean onlyMissingQuotes = format.chars()
.filter(ch -> formattedString.indexOf((char) ch) == -1)
.allMatch(ch -> ch == '\'');
if (onlyMissingQuotes) {
return 0;
}
}
TextComponent component = new TextComponent(formattedString);
component.getStyle().applyTo(parent.getStyle());
children.add(component);
return format.length();