-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MessageFormat formatters #653
Conversation
I've implemented this. It also doesn't output the pluralGenerator at all if it's not needed (the current version of globalize always outputs the cardinal one, even if no message needs it). |
I've changed the way messageformatters are compiled. Instead of this: Globalize.b955419430 = messageFormatterFn((function(plural, fmt, en) {
return function(d) {
return "Hello World number( " + plural(d.x, 0, en, {
one: "one task " + fmt[0](d.now) + " ",
other: d.x + " tasks " + fmt[1](d.now) + " "
});
}
})(messageFormat.plural, [Globalize("en").dateFormatter({
"date": "long"
}), Globalize("en").dateFormatter({
"date": "long"
})], Globalize("en").pluralGenerator({
type: "cardinal"
})), Globalize("en").pluralGenerator({
"type": "cardinal"
}), Globalize("en").dateFormatter({
"date": "long"
}), Globalize("en").dateFormatter({
"date": "long"
})); It now looks like this: Globalize.b955419430 = messageFormatterFn((function(en) {
var plural = messageFormat.plural;
var fmt = [].slice.call(arguments, 1);
return function(d) {
return "Hello World number( " + plural(d.x, 0, en, {
one: "one task " + fmt[0](d.now) + " ",
other: d.x + " tasks " + fmt[1](d.now) + " "
});
}
}), "call", Globalize("en").pluralGenerator({
"type": "cardinal"
}), Globalize("en").dateFormatter({
"date": "long"
}), Globalize("en").dateFormatter({
"date": "long"
})); The formatters are not duplicated by This required changing |
df1b90d
to
5e72dbf
Compare
I've cleaned this up, and it's mostly done. The remaining issues:
|
Ok, it's on my TODO list to review. |
5e72dbf
to
06effea
Compare
Any news here? |
This needs review. Basically, we need to make sure this change is backward compatible, and it works with globalize-compiler. I didn't find time to do it yet, but if someone could investigate that and post findings here, it would speed things up :) thanks |
I also have to document and add tests. I'll try to do that soon. |
Awesome, thanks @nkovacs
They are!! Thanks to @Strate for that too :) About the syntax, it would be good to (re-)evaluate existing solutions and digest a conclusion. Useful links:
|
@nkovacs are you use it now in some projects? I would megre you PR in current state and test it. |
Not yet, but please do test it. I've rebased it on master recently, but haven't had time to test it thoroughly. |
@nkovacs at least |
06effea
to
6da191b
Compare
I've added tests, but they fail because they need globalizejs/globalize-compiler#17 I ran into some issues with messageformat-parse: messageformat/parser#1 and messageformat/messageformat#175 The second one I've already started fixing. The first one I can also fix, but that would mean that this would no longer be parsed as two separate parameters ( The way ICU works is that after the second comma, everything until the |
I've implemented date raw and skeleton support. Raw works the same way ICU does: Skeleton is This requires messageformat/parser#3. |
Most globalize modules can now be used directly from within messages. Also fixes selectOrdinal not using the correct plural function. The messageformat compiler and runtime are forked from messageformat.js. Fixes globalizejs#563
messageformatterFn now uses the runtimeArgs generated by globalize-compiler instead of having them duplicated by messageFormatterRuntimeBind.
The new version adds a string "call" parameter after the formatter function. Old bundles will not have this parameter, so messageFormatterFn will use the old behavior.
No longer needed, since we use a forked version.
b946b53
to
c9d2460
Compare
Can you also update documentation please? Somewhere we need to list this new API.
I'd rather use skeleton by default (which is the recommended way users should customize their formats) and have a specific dateraw for the raw pattern. How can they pass presets like How does this implementation compare to https://github.com/messageformat/messageformat.js and https://github.com/yahoo/intl-messageformat/ please?
Please, is the update included in this PR? Or it requires any further action? |
Of course. Should I add it to doc/api/message/message-formatter.md?
I did it this way to keep it compatible with ICU. In ICU you have:
Both This PR supports that, plus:
I did it this way to make it compatible with ICU. However, since it's possible to overwrite the formatter function with
No, it's not, since messageformat-parser is downloaded from npm. I made a forked version, I could use that: https://www.npmjs.com/package/icu-messageformat-parser. |
It looks good. Thanks.
I understand, it's always good to follow a standard, but it's unfortunate ICU is doing it that way. Does ICU allow skeleton input? If you have time, please could you also compare to what Yahoo is doing (link above)?
Would this be needed in addition to messageformat/messageformat.js or would it replace it please? |
No, ICU doesn't allow skeleton input, unfortunately.
Messageformat.js isn't needed, the parts that were needed have been replaced by message/compiler.js and message/formatter-runtime.js (see #563 (comment)) |
Ok. Thanks.
Did you send a PR to the origin repo? Please, if so could you provide a link for reference?
Ok, that is well explained. Thanks! I see that you had reasons to drop messageformat/messageformat.js and to use a custom replacement. I also understand that the way globalize currently embeds messageformat/messageformat.js is hard to maintain over time. Having said that, there's a downside of duplicating what messageformat/messageformat.js does. We wouldn't take benefit of bug fixes and improvements done there... |
I mean I fixed them in messageformat-parser, not intl-messageformat-parser (messageformat/parser#3). intl-messageformat-parser is based on messageformat.js's parser (before it was a standalone package), but it's quite different. E.g. intl-messageformat-parser/intl-messageformat handles I also looked at https://www.npmjs.com/package/format-message-parse, it was slightly better with apostrophe escaping, but it also can't parse Then there's messageformat.js's |
Noting also here that I've reviewed the messageformat-parser PR. Overall, it's good, but ought to be split into two as the quote-escaping will change users' outputs, and therefore requires us to make a major version update. |
I am closing all old (and stalled) PRs |
Fixes #563