ICU MessageFormat句柄选择带有空白参数

时间:2019-03-22 14:38:29

标签: php translation icu

我想使用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。

1 个答案:

答案 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"]);