Javascript 如何使用Globalizejs验证ICU消息语法?
JavaScript中有几个i18n库可用,其中最完整的一个似乎是 在测试时,我发现发送无效ICU消息时出现问题。它似乎忽略了错误。举例如下:Javascript 如何使用Globalizejs验证ICU消息语法?,javascript,internationalization,globalization,javascript-globalize,Javascript,Internationalization,Globalization,Javascript Globalize,JavaScript中有几个i18n库可用,其中最完整的一个似乎是 在测试时,我发现发送无效ICU消息时出现问题。它似乎忽略了错误。举例如下: Globalize.loadMessages({ en: { test1: [ "You have {count, plural, one {# hot dog} one {# hamburger} one {# sandwich} other {# snacks}} in
Globalize.loadMessages({
en: {
test1: [
"You have {count, plural, one {# hot dog} one {# hamburger} one {# sandwich} other {# snacks}} in your lunch bag."
],
test2: [
"You have {count, plural, one {# hot dog} thisIsNotValid1 {# hamburger} thisIsNotValid2 {# sandwich} other {# snacks}} in your lunch bag."
]
}
});
console.log(Globalize( 'en' ).messageFormatter( 'test1' )({count: 1}));
// Output: You have 1 sandwich in your lunch bag.
// Expected output: exception thrown because the plural "one" is used multiple times.
console.log(Globalize( 'en' ).messageFormatter( 'test2' )({count: 1}));
// Output: You have 1 hot dog in your lunch bag.
// Expected output: exception thrown because the plural "thisIsNotValid1" and "thisIsNotValid2" are not valid.
有没有办法发现ICU语法无效,而不是默默地输出尽力结果?可以使用(或其修改版本)来检测您正在查找的无效语法
PS:感谢您在Stack Overflow和中提交此问题,感谢您回答这两个问题-仅供参考,我现在使用此解析器成功地检测到了错误:-它似乎在我描述的两种情况下都能正常工作。