mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Allow fallback components to translate with arguments
This commit is contained in:
parent
48b796d75e
commit
0f3d5c5859
2 changed files with 13 additions and 3 deletions
|
@ -42,14 +42,24 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer<
|
||||||
private final Pattern stringReplacement = Pattern.compile("%s");
|
private final Pattern stringReplacement = Pattern.compile("%s");
|
||||||
private final Pattern positionalStringReplacement = Pattern.compile("%([0-9]+)\\$s");
|
private final Pattern positionalStringReplacement = Pattern.compile("%([0-9]+)\\$s");
|
||||||
|
|
||||||
|
// Exists to maintain compatibility with Velocity's older Adventure version
|
||||||
@Override
|
@Override
|
||||||
public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) {
|
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
|
// Get the locale string
|
||||||
String localeString = MinecraftLocale.getLocaleStringIfPresent(key, locale);
|
String localeString = MinecraftLocale.getLocaleStringIfPresent(key, locale);
|
||||||
if (localeString == null) {
|
if (localeString == null) {
|
||||||
// Allow fallback components to take priority
|
if (fallback == null) {
|
||||||
|
// No fallback and no match for string; nothing will be translated/inserted
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// Fallback strings will still have their params inserted
|
||||||
|
localeString = fallback;
|
||||||
|
}
|
||||||
|
|
||||||
// Replace the `%s` with numbered inserts `{0}`
|
// Replace the `%s` with numbered inserts `{0}`
|
||||||
Pattern p = stringReplacement;
|
Pattern p = stringReplacement;
|
||||||
|
|
|
@ -13,7 +13,7 @@ protocol = "3.0.0.Beta1-SNAPSHOT"
|
||||||
raknet = "0.0.1.Final-SNAPSHOT"
|
raknet = "0.0.1.Final-SNAPSHOT"
|
||||||
mcauthlib = "d9d773e"
|
mcauthlib = "d9d773e"
|
||||||
mcprotocollib = "1.19.4-math2-SNAPSHOT"
|
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"
|
adventure-platform = "4.1.2"
|
||||||
junit = "5.9.2"
|
junit = "5.9.2"
|
||||||
checkerframework = "3.19.0"
|
checkerframework = "3.19.0"
|
||||||
|
|
Loading…
Reference in a new issue