globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 605 forks source link

Cannot escape pattern in curly braces with single quotes #837

Open mylonasartist opened 6 years ago

mylonasartist commented 6 years ago

Hello, thank you for this package. Could you please check if this is a bug. I am trying to escape a message pattern argument using single quotes. The argument is defined as index in curly braces. The problem is I have no luck to obtain the message that contains the unchanged pattern. Short code: ... `Globalize.loadMessages({ en: { escaped: "Escaped '{0}'" } });

Globalize.locale( "en" );

var escaped = Globalize.messageFormatter( "escaped" );

console.log( escaped() ); // here "Escaped {0}" is expected, but got "Cannot read property '0' of undefined" ` ... Output with error: return function(d) { return "Escaped '" + d["0"] + "'"; } ^

TypeError: Cannot read property '0' of undefined at eval (eval at MessageFormat.compile (D:\skre\projects\JavaScript\Globalize\EscapeTest\node_modules\globalize\dist\globalize\message.js:1820:13), :3:44)

Thank you.

rxaviers commented 6 years ago

We should update Globalize to use a newer messageformat version.