From 0e7a7588ec459cfb709a169083a921b8bc6fb643 Mon Sep 17 00:00:00 2001 From: rasmus123d <59487370+RasmusKD@users.noreply.github.com> Date: Sun, 16 Aug 2026 19:51:48 +0200 Subject: [PATCH] Collapse whitespace around color tags in translations A color tag is invisible once rendered, so a translation with whitespace on both sides of one shows a double space in chat, like the Danish /fly message: 'Set flytilstand {0} for' renders as 'flytilstand aktiveret for'. Comparing every locale's rendered strings against the English source finds the same mistake in about 400 strings across 38 locales, so fixing it string by string on Crowdin is not realistic, and new translations keep reintroducing it. Translated formats now collapse whitespace surrounding a primary or secondary tag to a single space before the format cache. Strings with the tag flush against a word on either side are unchanged. --- Essentials/src/main/java/com/earth2me/essentials/I18n.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/I18n.java b/Essentials/src/main/java/com/earth2me/essentials/I18n.java index 928bc06a7c8..a1fecbacd4d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/I18n.java +++ b/Essentials/src/main/java/com/earth2me/essentials/I18n.java @@ -36,6 +36,9 @@ public class I18n implements net.ess3.api.II18n { private static final String MESSAGES = "messages"; private static final Pattern NODOUBLEMARK = Pattern.compile("''"); + // A color tag is invisible once rendered, so a translation with whitespace on + // both sides of one shows a double space in chat. Many locales carry this. + private static final Pattern SPACED_COLOR_TAG = Pattern.compile("\\s+()\\s+"); private static volatile ExecutorService BUNDLE_LOADER_EXECUTOR = Executors.newFixedThreadPool(2); private static final ResourceBundle NULL_BUNDLE = new ResourceBundle() { @SuppressWarnings("NullableProblems") @@ -193,7 +196,7 @@ private String translate(final Locale locale, final String string) { } private String format(final Locale locale, final String string, final Object... objects) { - String format = translate(locale, string); + String format = SPACED_COLOR_TAG.matcher(translate(locale, string)).replaceAll(" $1"); MessageFormat messageFormat = messageFormatCache.computeIfAbsent(locale, l -> new HashMap<>()).get(format); if (messageFormat == null) {