Merge pull request #2481 from BentoBoxWorld/placeholder_translation

Placeholder translation
This commit is contained in:
tastybento 2024-08-22 16:54:38 -07:00 committed by GitHub
commit 8e3f368602
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 9 deletions

View File

@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.5.2</build.version>
<build.version>2.5.3</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>

View File

@ -505,12 +505,6 @@ public class User implements MetaDataAble {
private String replacePrefixes(String translation, String[] variables) {
for (String prefix : plugin.getLocalesManager().getAvailablePrefixes(this)) {
String prefixTranslation = getTranslation("prefixes." + prefix);
// Replace the [gamemode] text variable
prefixTranslation = prefixTranslation.replace("[gamemode]",
addon != null ? addon.getDescription().getName() : "[gamemode]");
// Replace the [friendly_name] text variable
prefixTranslation = prefixTranslation.replace("[friendly_name]",
isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
// Replace the prefix in the actual message
translation = translation.replace("[prefix_" + prefix + "]", prefixTranslation);
@ -530,6 +524,16 @@ public class User implements MetaDataAble {
if (player != null) {
translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation);
}
// Replace game mode and friendly name in general
// Replace the [gamemode] text variable
translation = translation.replace("[gamemode]",
addon != null ? addon.getDescription().getName() : "[gamemode]");
if (getWorld() != null) {
// Replace the [friendly_name] text variable
translation = translation.replace("[friendly_name]",
isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
}
return translation;
}

View File

@ -119,11 +119,16 @@ public class UserTest {
// Player
when(player.getServer()).thenReturn(server);
when(server.getOnlinePlayers()).thenReturn(Collections.emptySet());
@NonNull
World world = mock(World.class);
when(world.getName()).thenReturn("BSkyBlock");
when(player.getWorld()).thenReturn(world);
// IWM
when(plugin.getIWM()).thenReturn(iwm);
// Addon
when(iwm .getAddon(any())).thenReturn(Optional.empty());
when(iwm.getAddon(any())).thenReturn(Optional.empty());
when(iwm.getFriendlyName(world)).thenReturn("BSkyBlock-Fiendly");
user = User.getInstance(player);
@ -930,7 +935,7 @@ public class UserTest {
when(addon.getDescription()).thenReturn(new Builder("main", "gameAddon", "1.0").build());
p.setAddon(addon);
p.getTranslation(TEST_TRANSLATION);
verify(addon).getDescription();
verify(addon, times(2)).getDescription();
}
/**