Updating i18n Messages api to avoid unexpected formatting issues

15 views
Skip to first unread message

Alexis Hernandez

unread,
Jan 27, 2018, 9:49:33 PM1/27/18
to Play framework dev
The current methods for translating a message (like Messages#apply) specify the argument types for the message parameters as Any, while this could be useful in some situations, personally I think that it would be better to restrict the types, like receiving String types only, in this case you will be forced to format your parameters as you like instead of relaying on what java.text.MessageFormat does.

If this is something that could be merged, I would not mind to create a pull request, any comments?

Thanks.

James Roper

unread,
Jan 28, 2018, 6:59:26 PM1/28/18
to Alexis Hernandez, Play framework dev
Java's message formatting for numbers, dates etc is actually quite powerful, you can do things like specify different messages based on whether the number passed in is zero, one or many, for example:

There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.
The above message yields the following for 0, 1 or 2 files respectively:

There are no files.
There is one file.
There are 2 files.

Using this means you can encode locale specific rules around plurals, handling of zero, etc, which only works if you can work with numbers, so supporting just String won't work.

--
You received this message because you are subscribed to the Google Groups "Play framework dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework-dev+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Roper
Senior Octonaut

Lightbend – Build reactive apps!
Twitter: @jroper

Alexis Hernandez

unread,
Jan 29, 2018, 12:30:33 AM1/29/18
to Play framework dev
That's an interesting use case for the Java message formatter, thanks.
Reply all
Reply to author
Forward
0 new messages