I have {numCats, number} cats.
Almost {pctBlack, number, ::percent} of them are black.
{key, select, matches}
可以作为条件判断选择使用,例如:
{gender, select,
male {He}
female {She}
other {They}
} will respond shortly.
甚至进行嵌套:
{taxableArea, select,
yes {An additional {taxRate, number, percent} tax will be collected.}
other {No taxes apply.}
}
{key, plural, matches}
复数格式的存在是因为很多语言会对复数处理不太一样。
例如:
Cart: {itemCount} {itemCount, plural,
one {item}
other {items}
}
You have {itemCount, plural,
=0 {no items}
one {1 item}
other {{itemCount} items}
}.
使用#可以格式化为{key,number}
You have {itemCount, plural,
=0 {no items}
one {# item}
other {# items}
}.
{key, selectordinal, matches}
和上面复数有点像,也是个类似复数的表现:
It's my cat's {year, selectordinal,
one {#st}
two {#nd}
few {#rd}
other {#th}
} birthday!
不同之处是这种语法会被映射到一个map
富文本格式化
icu支持富文本,但是这个像html的标签并不是xml或者html标签。
Our price is <boldThis>{price, number, ::currency/USD precision-integer}</boldThis>
with <link>{pct, number, ::percent} discount</link>
转义
语法必然会有转义 使用’进行转义
"This is not an interpolation: '{word}"//→ "This is not an interpolation: {word}""These are not interpolatons: '{word1} {word2}'"//→ "These are not interpolatons: {word1} {word2}""'<notATag>"//→ "<notATag>""'<notATag>hello</notATag>'"//→ "<notATag>hello</notATag>"