[haiku-commits] Re: haiku: hrev47971 - in src: tests/kits/locale servers/mail kits/tracker add-ons/mail_daemon/inbound_filters/notifier kits/locale

  • From: pulkomandy <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 7 Oct 2014 11:50:15 +0200

On Tue, Oct 07, 2014 at 11:26:14AM +0200, Axel Dörfler wrote:
> Am 07.10.2014 11:09, schrieb pulkomandy:
> >(or "any number ending in 2, 3 or 4, but not 12,13,14"). That's hardly
> >a less wordy alternative.
> 
> Indeed, that makes sense. Still, is there a less wordy syntax available?

Not that I know of, but for "simple" languages like english, french and
german, the choice format can be used.

> >They should work as is, since
> >Java also implements this using ICU.
> 
> Nope, it doesn't. It's all native Java code.

Sorry, I'm not being accurate here. Some implementations of the Java
libraries use ICU (either the C version through native calls or the Java
version) for this. Oracle's one doesn't.

But the outcome is pretty much the same: we are exposing the ICU syntax
directly, and it closely follows what's available in other Java
implementations.

There is still room for improvement in the BMessageFormat API, however:
- Only one int32 argument can be used. This rules out some complex uses
  like formatting depending on both the gender and number, formatting
  floating point numbers, etc.
- Arguments are referenced only by positional notation (hence all
  formatting rules look like "{0 ...}". There is support for named
  arguments, but we then have to pass the names alongside the values.

One possible solution is to store all the arguments in a BMessage, so
they can be referred by name. We can then convert the message into an
icu Formattable array (or make a wrapper FormattableMessage) to access
the message contents. It would work approximately like this:

BMessage data;
data.AddInt32("count", 43);
data.AddString("name", "foo");

BString result;
BMessageFormat().Format(result, "{count, plural, one{# message}
other{# messages}} for account {name}", data);

// result: "43 messages for account foo"

-- 
Adrien.

Other related posts: