I am using MessageFormat (part of the intl
extension) in PHP. The extension uses ICU 4.6.1.
However, the problem isn't with PHP.
I would like to format a piece of string by making a decision on the first token {0}
:
{0}
is 0
, the text should be a
1
, the text should be b
c
I understand that this could be done with plural
, =0
for the 0
case, but through my testing, it doesn't seem to work, most likely because offsets and custom plurals were introduced in 4.8.
I am thus, trying to accomplish that using select
:
{0, select, 0 {a} other {{0,plural,one{b}other{c}}}}
However, for some reason, the message formatter was unable to format the above and returns false
(couldn't format).
Why is this the case? Is there a problem with my syntax?
Quick update: After some digging, it seems that I cannot use select to match values that start with a number. Are there any ways around this?
Another update: Updated to ICU 49.1.2 and intl
3.0.0a2. I can now use =0
, =1
, etc, but this has stopped working (was working previously):
{0}{0, plural, one{a} other{b}}
where as this works:
{0, plural, one{a} other{b}}
I ended up upgrading to the latest version of intl
and ICU 49.1.2.
However, once that was done, this would not work:
{0}{0, plural, one{a} other{b}}
But this worked:
{0, plural, =0{a} one{# b} other {# c}}