如何使用 Globalizejs 验证 ICU 消息语法?
How to validate ICU messages syntax using Globalizejs?
JavaScript 中有一些可用的 i18n 库,最完整的库之一似乎是 GlobalizeJs。
在测试时,我发现发送无效的 ICU 消息时出现问题。它似乎忽略了错误。以下示例:
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 语法无效而不是默默地输出最大努力的结果?
可能可以使用 https://github.com/messageformat/messageformat/tree/master/packages/parser(或其修改版本)来检测您要查找的无效语法
PS:感谢您在 Stack Overflow 和 https://github.com/globalizejs/globalize/issues/874
中提交此问题
JavaScript 中有一些可用的 i18n 库,最完整的库之一似乎是 GlobalizeJs。
在测试时,我发现发送无效的 ICU 消息时出现问题。它似乎忽略了错误。以下示例:
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 语法无效而不是默默地输出最大努力的结果?
可能可以使用 https://github.com/messageformat/messageformat/tree/master/packages/parser(或其修改版本)来检测您要查找的无效语法
PS:感谢您在 Stack Overflow 和 https://github.com/globalizejs/globalize/issues/874
中提交此问题