[erlang-questions] rberl: parse Java's Resource Bundles in Erlang

Richard O'Keefe ok@REDACTED
Tue Jun 2 04:45:14 CEST 2009


On 30 May 2009, at 12:35 am, Dmitrii Dimandt wrote:

> http://github.com/dmitriid/rberl/
>
> This is a very small ad-hoc library I threw together to parse Java's  
> resource bundles. It turns out i like it more than gettext :)
>
> There's a TODO list on my mind. One question that bugs me is:
>
> Java's RB's allow stuff like this:
> At {2,time,short} on {2,date,long}, we detected {1,number,integer}  
> spaceships on the planet {0}.
>

This partly solves a real problem, namely that when you
internationalise a message with parameters, the order of the
parameters may need to change.  UNIX C compilers handle that
with the "<parameter number>$" modifier in printf() strings.
[Considering that parameters of different types may be different
sizes, I have no idea how they make that work.]

The residual problem is that the {...} thingies are little programs
in a specialised and inadequately powerful language.  Consider the
that "1 spaceships" is quite simply WRONG in English.  So you need
to consider singular/non-singular for English.  But wait!  Some
languages have singular (1)/dual (2)/plural (everything else).
[Maori does that with pronouns, so if you wanted to include the
equivalent of "it/them" in a message, you'd need three cases.
Old English did the same.]  But wait!  Some languages actually have
singular/dual/paucal ("a few")/plural.  But wait!  There are languages
where you don't say "N thing(s)" but "N <classifier> thing(s)", and
the numeral classifier depends on what kind of thing.  That's all
very well until the day that the 'thing' part becomes one of the
parameters as well.  Suppose that we want
	tally(N, Thing) -> "There were <N> <THINGS>"
and that
tally(2, errors) should be "There were 2 'social-lapses' errors" but
tally(2, exceptions) should be "There were 2 'events' exceptions".

What do Java programmers do about that?

Of course, this is just a grossly oversimplified presentation of the
problem of generating internationalised messages.

But as long as you remember that
  - a mapping from parameters to messages is a function
  - functions are data
you will be able to see opportunities where Java programmers
(should) see obstacles.




More information about the erlang-questions mailing list