javascript - 如何使用 Globalizejs 验证 ICU 消息语法?
问题描述
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 语法无效,而不是默默地输出尽力而为的结果?
解决方案
推荐阅读
- redirect - 将旧域 url 从旧主机重定向到具有新主机的新域 url,但各个页面的名称不同
- python - 尝试绘制从系列创建的数据框时,在 matplot lib 中获取元组索引超出范围错误
- swift - 转换为 Swift 3 时出现 UITableView 错误
- r - 关于Stata中forvalues的等效R代码
- c# - IdentityServer4 和 Angular:使用隐式流程注销
- azure - How can I use AWS ami in Azure to launch a VM in azure?
- amazon-web-services - AWS transit gateway/AWS VPN tunnel never goes up
- excel - 无法识别“类型不匹配”错误的来源
- php - 用不同的数量更新相同的id(只更新最先出现的id)
- wix - 如何自动测试可通过 UAC 安装的 MSI?