If/else in FormatJS / React-intl



是否有可能在FormatJS消息中有if/else ?

例子我有一个布尔变量isDay,它应该决定显示什么消息。当true时,我想显示&;day &;当false时,我想显示Night

// message string
message = "Day";
// React component
<FormattedMessage
id="message"
values={{isDay: true}}
/>

我希望能够做这样的事情:

message = "{if isDay}Day{else}Night{endif}";

我知道上面不是实际的语法,但想知道这样的东西是否可能与FormatJS?

找到使用ICU消息选择语法的解决方案。

message = "{isDay, select, true {Day} other {Night}}";

最新更新