我想使用ICU MessageFormat handling complex arguments翻译文本,但是我找不到为空字符串/空参数添加选择项的方法:
{variable, select,
empty {The translation when variable is null / blank}
other {The translation when variable is not null}
}
当给定empty
为空值时,我想显示variable
转换,但是我找不到正确的语法来实现这一点。
这将返回语法错误:
{variable, select,
'' {The translation when variable is null / blank}
other {The translation when variable is not null}
}
我在PHP中使用ICU MessageFormat。
答案 0 :(得分:0)
我找不到在ICU消息中使用空字符串引用的方法。我会这样:
$variable = "foobar";
echo msgfmt_format_message("en_US", "{variable, select,
empty {The translation when variable is null / blank}
other {The translation when variable is not null}
}", ["variable" => empty($variable) ? "empty" : "other"]);