-
Notifications
You must be signed in to change notification settings - Fork 181
IntlUtils.loadLocaleData seems like it could be improved #52
Comments
I agree with you @robink, I couldn't find a better solution. The problem here is to download locale data only for the user's language before rendering the app. With this script we can group and
Dynamic requires wouldn't work because webpack cannot know what to put inside them. Which error did you get? An alternative may be to not use webpack and try a more custom way, maybe using a fetchr service or, why not, a store. I'm open for new ideas :-) |
I'm also interested in this topic. Looks like only one way of doing that is to share translation data on the REST end-point and download it on the server/client side with fetchr. |
@dmitry thanks for joining in :-) What do you mean for translation data ? We need:
In my implementation, "messages" are already fetched server-side and dehydrated in the The weak part is the way The bad part is that we need to hand-write the modules to be As alternative, chunks could be set in the webpack config: entry: {
main: "./client.js",
// define chunks required for i18n,
"i18n-it": ["intl/locale-data/jsonp/it", "react-intl/dist/locale-data/it"],
"i18n-es": ["intl/locale-data/jsonp/es", "react-intl/dist/locale-data/es"],
"i18n-en": [] // default for both intl and react-intl, no need to load anything in this chunk
} then, a fetchr service could read the content of those chunks (maybe accessing the webpack stats json) and somewhere we could However, it would not be enough, as we need to discern browsers not supporting entry: {
main: "./client.js",
// define chunks required for intl,
"i18n-it": ["react-intl/dist/locale-data/it"],
"i18n-it-with-intl": ["intl/locale-data/jsonp/it", "react-intl/dist/locale-data/it"],
"i18n-es": ["react-intl/dist/locale-data/es"],
"i18n-es-with-intl": ["react-intl/dist/locale-data/es"],
"i18n-en": [], // default for both intl and react-intl, so no need to load anything in this chunk
"i18n-en-with-intl": []
} It does get more complex. I still believe the ... or I'm just overthinking the problem. Other ideas? |
We could make a webpack plugin loading a set of locales. The plugin should receive an array of the scripts to be included for each language. It could work with react-intl, intl, moment or any other library locale data sets |
@gpbl Thank you for providing this awesome repository. I made a loader that does exactly what you need to reduce |
woah @danilobuerger you rock!! Does it even work with react-intl 2.0? |
@gpbl yes, only with 2.0 as it requires the |
But i guess if you need to support 1.x as well, it would be a very simple case to just check if |
@danilobuerger Awesome ! Well done! No i don't think is worth having it working on react-intl 1.0. Sure I'd like to have the time to update this repo 💦😄 |
@gpbl if you do, you should also consider redux, would reduce a lot of additional boilerplate related to intl |
👍 see redux500 – still work in progress: I'm just finished migrating a flux app to redux and i've got much more experience with it. |
I'm not a very big fan of this part: https://github.com/gpbl/isomorphic500/blob/master/src/utils/IntlUtils.js#L64-L107
When I add a locale to one of my webapps, I love to simply have to create a new locale file, like en.js, declare it as being available in my config file, like dev.js, and that's it.
What is being done in loadLocaleData seems to go against the DRY principle.
I've tried to refactor the switch using dynamic requires but webpack is now complaining about it. Any thoughts?
The text was updated successfully, but these errors were encountered: