-
Notifications
You must be signed in to change notification settings - Fork 215
Node.js support and npm package #20
Comments
👍 |
1 similar comment
👍 |
This is partly covered by #22. I updated the issue with a Todos list. |
hey @andyearnshaw any update on this one? |
Nothing to speak of yet. It's a priority for Intl.js (along with completing the flexible building stuff), but I'm just swamped with work at the moment and between that and time spent with my family, I haven't been able to work on personal projects much. If @ericf still wants to open a PR for it, then I'll make some time to review it, that's absolutely fine with me. |
Many thanks, @drewfish. Sorry I've been quiet, guys, I've had a lot of personal stuff going on over the past week. Anyhow, I've reviewed and merged but I'm still a little unsure on how I'm going to tackle Intl.js as an NPM module, I think it needs a little more work before publishing. Right now, Intl.js requires that the locale data is provided by the implementer using the proprietary Intl.__addLocaleData() function. If we publish to NPM as-is, the locale data would be downloaded along with Intl.js, but Intl.js isn't aware of it and will not load it on-demand. This means anyone using Intl.js would still need to separately download the data or look for the One option would be to add a small internal function to check if we're running under node and then synchronously load the data instead of throwing the error. Any thoughts? p.s. thanks for all the interest! |
@andyearnshaw no worries, we will help in any way we can to get all the pieces in place so you just need to review them when you get a chance. About loading data:
And that is going to do the exact same, but just adding specific locales instead of all. I will issue a PR to demonstrate this proposal. |
Would it be possible to wrap it up in a way that the require is hidden?
So under the hood it would do:
|
@apipkin I don't like that because: a) it is an API change in anyway, I issued the PR #26 with the proposal. |
Also, about the question of how to use this thing in nodejs from @andyearnshaw, I think PR #26 describes how is this going to be used. We can add a section dedicated to NodeJS in the README. /cc @drewfish |
@caridy fair enough :) |
I dislike the idea that |
For the client-side (browser) I don't think there's any sugar we can add to make it easier to load locales, since the URL used to load the locale data is very application-specific. So, the only way to make this library behave the same in both environments is to have the user specify the locale data specifically (current behavior). I like the idea of adding server-specific sugar. There still are people writing node.js applications that don't have much client-side behavior (or, it's not localized). As well, there are other sources of locale metadata besides this package. (Those sources might need to be massaged to fit into this library.) |
I think it would be possible for a config to provide a way to have the server side sugar (suggested earlier) become effective on the client side. Again being sychronous and all that. But it could load jsonp data instead and load it later. There again, if that route were taken, it could be something like:
or something along those lines. Again, having it as sugar would lower the front step to getting the system up and running with i18n, but could easily be improved upon by requesting the data in another step and injecting it |
@andyearnshaw using this in the browser requires the person to figure out their own resource bundle loading strategy, I think we should do the same on huge server. The manual loading of resources via Are you worried about the dunder function being part of the public API? |
Ok, ok, let me step back and clarify few things: a) this is a polyfill, this is not a library, which means we are trying to make up something that is suppose to be there in newer browsers. in other words, when using it in nodejs, you will probably use it like this:
that will cover the case where you have nodejs running with the i18n flag (which is coming soon), but also the case where you have an older version of nodejs or the default nodejs configuration. take in consideration that global.Intl is going to have all the locales info available, and you have to do nothing. Which is exactly what the polyfill should be doing. b) It is true that this is an expensive operation (requiring all files one by one), but it doesn't have to be like that, we can fix that, see point 3. c) I'm ok inverting the equation and saying that the default Intl.js module will come without langs, but loading the module with all locales data in a single require is a most, so, we could do something like:
where d) for the client side, ideally people will use browsify, or some sort of build process to provision |
@caridy seeing it from that perspective, i think you raise a good point, but I believe (and correct me if I'm wrong) |
yes, |
Wow, busy conversation! I started writing this reply a few hours ago but I didn't get the chance to finish it until now so please disregard anything that's already been said. I'm in agreement with @drewfish, I wouldn't be happy loading the entire data with I'm toying with the idea of:
A potential problem with this approach is choosing a value to be returned by WTR to complete, built-in locale data, I remember starting a solution in the flexibleBuild branch that would have compressed the data by reusing objects where the data is identical (this occurs a lot with number format symbols and datetime formats). IIRC, the approach I took didn't pan out, but I wouldn't mind revisiting it at some point. |
How do you feel about an optional |
Side note about |
@drewfish: I'd be OK with that. It's better to give both options as many might prefer the lower footprint of loading data on-demand. @caridy: yeah, I could see |
on the server side DefaultLocale() can't be the one from Accept-Language header? |
@lwelti Yeah I think that's what Caridy meant by "the locale detection is, in most cases, bound to the request information". Since this library has no concept of a connect/express request, it is up to the user of this library to manage the request object to find the locale to use. |
Just to clarify, we cannot use DefaultLocale() on the server side because the same process will be responding to multiple request but |
|
🤘 |
great!! |
features.js compatibility browser support in whiteboard on node.js |
We are interested in using
Intl.js
in browsers which don't have the built-inIntl
APIs and in Node.js.It's still up in the air on whether Node.js binaries will ship with v8-i18n linked. There's a long discussion with [inaccurate] worries about the size of bundling the required parts of ICU. If this stays a compile-time flag for Node.js, it effectively means that the
Intl
APIs will not exist in Node.js :(See: nodejs/node-v0.x-archive#4689 (comment) and nodejs/node-v0.x-archive#6371
I would like to hedge this by being able to use this polyfill as an npm package and run it in Node.js. Would you be on board with adding the umd wrap (or similar) around this code instead of assuming
window
exists in the runtime? Also would you be on board with publishing this as an npm package?I am willing to open a PR for this, but I want to make sure that you're on board with this idea before I do so. Thanks!
Todos:
window
The text was updated successfully, but these errors were encountered: