So I am trying to add translations to my plugin. I have a TranslationHelper almost identical to the SpongeAPI one, and it works with normal strings. However when I try to format a string with it I get MissingFormatException errors even when the arguments are correct.
In other words if I do this:
String.format("You have %.2f", 10.567)
I get the correct output of 10.57;
However if I do:
t("You have %.2f", 10.567)
I get the following error message:
net.minecraft.util.ChatComponentTranslationFormatException: Error while parsing: TranslatableComponent{key='You have %.2f', args=[10.567], siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}} at net.minecraft.util.ChatComponentTranslation.func_150269_b(SourceFile:109) ~[hz.class:?] at net.minecraft.util.ChatComponentTranslation.func_150270_g(SourceFile:51) ~[hz.class:?] at net.minecraft.util.ChatComponentTranslation.childrenIterator(SourceFile:71) ~[hz.class:?] at org.spongepowered.common.text.ChatComponentIterable.iterator(ChatComponentIterable.java:47) ~[ChatComponentIterable.class:1.8-1577-2.1-DEV-0] at org.spongepowered.common.text.ChatComponentIterator.next(ChatComponentIterator.java:70) ~[ChatComponentIterator.class:1.8-1577-2.1-DEV-0] at org.spongepowered.common.text.ChatComponentIterator.next(ChatComponentIterator.java:38) ~[ChatComponentIterator.class:1.8-1577-2.1-DEV-0] at net.minecraft.util.ChatComponentStyle.toPlain(SourceFile:81) ~[hj.class:?] at org.spongepowered.api.text.Text.toPlain(Text.java:121) ~[Text.class:1.8-1577-2.1-DEV-0] at org.spongepowered.common.text.SpongeTextFactory.toPlain(SpongeTextFactory.java:61) ~[SpongeTextFactory.class:1.8-1577-2.1-DEV-0] at org.spongepowered.common.text.SpongeTextFactory.toPlain(SpongeTextFactory.java:56) ~[SpongeTextFactory.class:1.8-1577-2.1-DEV-0] at org.spongepowered.api.text.Texts.toPlain(Texts.java:552) ~[Texts.class:1.8-1577-2.1-DEV-0] at com.endernetwork.commands.balance.CommandBalance.process(CommandBalance.java:142) [CommandBalance.class:?] at org.spongepowered.api.util.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:340) [SimpleDispatcher.class:1.8-1577-2.1-DEV-0] at org.spongepowered.api.service.command.SimpleCommandService.process(SimpleCommandService.java:250) [SimpleCommandService.class:1.8-1577-2.1-DEV-0] at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:80) [cl.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:812) [rj.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:791) [rj.class:?] at net.minecraft.network.play.client.C01PacketChatMessage.func_180757_a(SourceFile:37) [lu.class:?] at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(SourceFile:9) [lu.class:?] at net.minecraft.network.PacketThreadUtil$1.onProcessPacket(SourceFile:63) [ih.class:?] at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) [ih.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_51] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) [FMLCommonHandler.class:?] at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:656) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:364) [po.class:?] at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:598) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51] Caused by: java.util.MissingFormatArgumentException: Format specifier '%.2f' at java.util.Formatter.format(Formatter.java:2519) ~[?:1.8.0_51] at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_51] at java.lang.String.format(String.java:2928) ~[?:1.8.0_51] at net.minecraft.util.ChatComponentTranslation.func_150269_b(SourceFile:104) ~[hz.class:?] ... 28 more
My TranslateHelper class (where t is defined):
public class EnderTranslateHelper {
private static final Function<Locale, ResourceBundle> LOOKUP_FUNC = new Function<Locale, ResourceBundle>() { @Nullable @Override public ResourceBundle apply(Locale input) { return ResourceBundle.getBundle("com.endernetwork.Translations", input); } };
private EnderTranslateHelper() {} // Prevent instance creation
public static Text t(String key, Object... args) { return Texts.of(new ResourceBundleTranslation(key, LOOKUP_FUNC), args); }
}
Anyone know why I am getting this error? Is it something on how I format my string? Or is there something else that is wrong? Thanks for any help