I'm currently using the I18NBundle
(wiki | docs) package from LibGDX to do some internationalization for my game. the I18NBundle
internally uses the java MessageFormat
(docs) to format strings such as this:
// The string to format.
shields = Shields: {0, number, integer}
// Do the formatting
bundle.format("shields", 5);
>> Shields: 5
It can also do conditionals like so:
// # = if exact
// < = if greater than
shields = Shields: {0, choice, 0# No Shields! | 1# One Shield! | 1< {0, number, integer} Shields!}
bundle.format("shields", 0);
>> Shields: No Shield!
bundle.format("shields", 1);
>> Shields: One Shield!
bundle.format("shields", 5);
>> Shields: 5 Shields!
Now I'm trying to compare two input parameters to each other. I tried this:
// If parameter 1 is greater than parameter 0...
score = Score: {0, choice, {1}< {0} New high score! | {0}}
bundle.format("score", newScore, highScore);
// Expected Output if new score is lesser than high score
bundle.format("score", 1, 5);
>> Score: 1
// Expected output if new score is greater than high score
bundle.format("score", 7, 5);
>> Score: 7 New high score!
But this throws an exception since it is invalid formatting. So my question is: Is it possible to compare two input parameters to each other when using ChoiceFormat
?
new Object()
) it appears in the same way as if you would doSystem.out.println(new Object())
. \$\endgroup\$ – Charanor Jun 14 '17 at 20:52number, date, time, choice
(andString
if you don't supply a type), no boolean or other types allowed! \$\endgroup\$ – Charanor Jun 14 '17 at 21:09