8
year.of.birth={0} was born on {1}

If I pass 2000 or 2008 to {1} the value gets parsed as 2,000 or 2,008. 

I don't want the commas as part of my translated string. How should I avoid this?

user339108
  • 12,613
  • 33
  • 81
  • 112

1 Answers1

17

The easy way is to pass them as Strings:

msg.format("year.of.birth", name,  String.valueOf(2008));

An alternative is to specify the number format in the message resource (but I would only do that if the format can vary between locales):

year.of.birth={0} was born in {1,number,####}
Thilo
  • 257,207
  • 101
  • 511
  • 656
  • hm, why a downvote here.. +1 from me. The way MessageFormat works is - it checks the type and applies a formatter. So no way to work around that in an easier way. – Bozho Dec 29 '10 at 12:21
  • Yes, correct way to use patterns with MessageFormat if you want to display it a particular way. +1 – LudoMC Dec 29 '10 at 12:28
  • Since 2008 is apparently a year, you can also use Date instead of Integer (`{1,date,yyyy}`) – Thilo Dec 29 '10 at 12:31