-
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
Message: Support ICU MessageFormat using slexaxton/messageformat.js #321
Conversation
rxaviers
commented
Sep 29, 2014
- Implement Support ICU MessageFormat #265
- Plural generator
- Functional tests
- Docs
- slexaxton/messageformat.js license (debeaf4)
- example
The first issue I hit passing Globalize's plural fn to MessageFormat is that MessageFormat's compiled fn can't find variable |
Can we change the compiled function to actually expect the plural function as a parameter? I'm hacking/experimenting that now. |
Hey @rxaviers - looking at this now. Things are looking pretty green. What's your read on what we should change in messageformat to support your use-case? |
@SlexAxton, thanks for asking. I need to pass a plural function to messageformat. Currently, this is only possible if the function is self-contained or if it refers to globals. A simple test case demonstrating what I mean: https://gist.github.com/rxaviers/ec8443f489f1d8d0d454. So, the very first minimal change I need is to be able to pass the plural function as a parameter to the compiled function. That's the easiest part and I should be able to create a custom In this PR, I add a "runtime" hack to change that by replacing such occurrences, and it works as expected. I've initiated a change in this branch. But, some tests still fail (I'm running tests with Overall, is this something that could be changed in messageformat in your opinion? Ideally, I wondered if I could access the core MessageFormat parts more directly. If your code were modularized like modernizr or this repo, I could access the source pieces instead of the bundle. Perhaps that would make it easier. Since, MessageFormat currently involves a build step, nothing would change on that regard. What do you think? |
@SlexAxton If you are open to changing your API slightly (approximating to Strawman Draft), we could have messageformat/messageformat#65. This would definitely solve the above. |
@rxaviers, I really like what you did replacing So I sort of completed what you started, here. That includes updates to Internally,
I know the question wasn't addressed to me, but can you clarify what you mean? Because I don't think there's really that much that can be modularized further from messageformat.js... |
Yea, I'm definitely open to supporting those use cases (especially not relying on local or global variables only). I'm a big fan of this change: https://github.com/eemeli/messageformat.js/compare/fix-x-plural-fn?expand=1 -- When we were initially discussing how to do this, this was what I was trying to advocate for (having the functions just available on the runtime instead of compiled into the output), so I'm very much in favor of these changes.
I agree both that modularization is a good thing, but also with @eemeli in that I'm not sure what we could pull out. |
Awesome, excellent guys. Thank you for the prompt answers. @eemeli thanks for the super speedy commits. By the way, I've updated this branch using the latest code and I could remove all the hacks! Great!
It works for me :). We could rethink that on messageformat/messageformat#65. @SlexAxton and @eemeli,
I don't want to distract you with that. So, we can first focus on messageformat/messageformat#65. So, please, ignore it for now. |
8afd6bd
to
18a5d50
Compare
@SlexAxton any update on the license? That's the only blocker for this to land (adding support for message format to Globalize). |
If someone can PR adding the necessary license to the messageformat repo, On Thu, Dec 11, 2014, 9:11 AM Jörn Zaefferer [email protected]
|
cce9b7a
to
56edc4f
Compare
@@ -15,6 +15,7 @@ | |||
"devDependencies": { | |||
"make-plural": "eemeli/make-plural.js#2.1.2", | |||
"es5-shim": "3.4.0", | |||
"messageformat": "SlexAxton/messageformat.js#302a46a38d511de3b499f9ce0d18289e9fbd92b3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be replaced with a tag once the liencese change is tagged, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! Or at least to point to debeaf4 (new license in place)
@@ -1,6 +1,6 @@ | |||
{ | |||
"scripts": { | |||
"preinstall": "npm install cldr-data-downloader", | |||
"postinstall": "./node_modules/cldr-data-downloader/bin/download.js -i bower_components/cldr-data/index.json -o bower_components/cldr-data/" | |||
"postinstall": "node ./node_modules/cldr-data-downloader/bin/download.js -i bower_components/cldr-data/index.json -o bower_components/cldr-data/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't really belong in this PR, does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops it doesn't. I've extracted this change and landed this piece on master. Rebased.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it still showing the diff here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated origin/master. But, the it still show up to me also. Although:
It doesn't show up to me running git diff origin/master..origin/fix-265-message-format
. So, a github delay/issue?
f182ef5
to
309ea0d
Compare
|
||
QUnit.test( "should return the loaded translation", function( assert ) { | ||
assert.messageFormatter( "pt", "amen", "Amém" ); | ||
assert.messageFormatter( "zh", "amen", "阿门" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could add an assertion that uses the root locale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, merge this test with the one below, since they use the same test data/setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are in two different sections, because they test two different levels of implementation support.
All done. |
0a22be1
to
6319478
Compare