'How to express lists in ICU
I'm trying to get into ICU syntax and would like to be able to express lists in the ICU message format.
For instance, given the data:
items:
- cool
- handy
- neat
I would like to be able to generate a messages like:
StackOverflow is cool, handy, and neat.
StackOverflow is cool and handy and nice.
ie. I would like to be able to define how to construct lists.
Is this at all possible within the ICU message syntax?
Solution 1:[1]
As far as I know, ICU message syntax does not support lists.
A potential workaround would be to check if your platform supports lists in their localization implementation (e.g. Android) or to wrap that "list logic" into the ICU Select kind of message.
ICU Select message example:
{
type,
select,
comma {StackOverflow is cool, handy, and neat.}
and {StackOverflow is cool and handy and nice.}
other {StackOverflow is: cool, handy, and nice.}
}
Note, ICU messages can be clumsy and hard to maintain.
Some free online ICU editors can help you to easily check and validate them (e.g. DevPal ICU message editor).
Solution 2:[2]
ICU has a ListFormatter. You can use that separately and then include it as a string in the message format.
There is a new working group discussing the next generation of message formatting, and there is already an issue discussing list formatting.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Brad |
Solution 2 | Steven R. Loomis |