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 语法无效,而不是默默地输出尽力而为的结果?