Allow fallback components to translate with arguments

This commit is contained in:
Camotoy 2023-04-18 19:07:55 -04:00
parent 48b796d75e
commit 0f3d5c5859
2 changed files with 13 additions and 3 deletions

View File

@ -42,13 +42,23 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer<
private final Pattern stringReplacement = Pattern.compile("%s");
private final Pattern positionalStringReplacement = Pattern.compile("%([0-9]+)\\$s");
// Exists to maintain compatibility with Velocity's older Adventure version
@Override
public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) {
return this.translate(key, null, locale);
}
@Override
protected @Nullable MessageFormat translate(@Nonnull String key, @Nullable String fallback, @Nonnull String locale) {
// Get the locale string
String localeString = MinecraftLocale.getLocaleStringIfPresent(key, locale);
if (localeString == null) {
// Allow fallback components to take priority
return null;
if (fallback == null) {
// No fallback and no match for string; nothing will be translated/inserted
return null;
}
// Fallback strings will still have their params inserted
localeString = fallback;
}
// Replace the `%s` with numbered inserts `{0}`

View File

@ -13,7 +13,7 @@ protocol = "3.0.0.Beta1-SNAPSHOT"
raknet = "0.0.1.Final-SNAPSHOT"
mcauthlib = "d9d773e"
mcprotocollib = "1.19.4-math2-SNAPSHOT"
adventure = "4.13.1-20230408.192716-3"
adventure = "4.14.0-20230418.205641-5"
adventure-platform = "4.1.2"
junit = "5.9.2"
checkerframework = "3.19.0"