[英]How to remove currency symbol, when formatting currency using Globalizejs library?
[英]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 中提交此問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.