-
Notifications
You must be signed in to change notification settings - Fork 165
Uplift i18n code to use dynamic imports #1720
Comments
// Dynamic import for translations
const loadArTranslations = (callback, scope) => {
import( /* webpackChunkName: "ar-translations" */'./ar.js')
.then(module => { callback.call(scope, module);})
.catch(error => { console.log(error) });
}; // Dynamic import for intl data
const loadArIntl = () =>
import( /* webpackChunkName: "ar-intl-local" */'intl/locale-data/jsonp/ar.js')
.then(module => {})
.catch(error => { console.log(error) }); // Dynamic import for intl polyfill
import( /* webpackChunkName: "intl-polyfill" */'intl')
.then(module => {
loadIntl(locale);
loadTranslations(locale, callback, scope);
})
.catch(error => { console.log(error) }); |
They've added support for dynamic imports in node_modules, in create-react-app v2. create-react-app explicitly prevents usage of Edit: I've explored this some and I was able to get a variation of terra-base / terra-i18n code to work with create-react-app, but had to modify some code. The aggregated translations pre-build tool would need to support outputting translation and intl loader files that use dynamic imports. In terra-core, we use These instances of In create-react-app, we wouldn't need to use the This leaves the At first, I thought it would be challenging to get terra-base/terra-i18n (code-splitting for translations) working in CRA v2 without ejecting, but it seems possible, if we lift the Until then, it may be easier to show users that want to use CRA v2 how to set up react-intl's |
Leaving this here in case anyone has issues with Create React App 2. Discussed with @bjankord offline - CRA2 consumers will also need to add |
With the work for #1941, we'll be removing defaultIntlLoaders.js, defaultTranslationsLoaders.js so that will resolve the |
This has been resolved in [email protected]/[email protected] |
Feature Request
Description
Currently, we use
require.ensure
to dynamically load i18n data based on what the current locale is set as. This is based on the recommendation from the Intl polyfill we used. This has worked well, however, webpack recommends using dynamic imports overrequire.ensure
. There is a possibilityrequire.ensure
becomes deprecated, however that doesn't seem likely yet.This issue is to start discussion on the update.
The text was updated successfully, but these errors were encountered: