Skip to content

i18n and code splitting #5433

@stereobooster

Description

@stereobooster

Is this a bug report?

No, rather a feature request.

i18n

There are ways to extract keys for internationalisation, like:

Those methods can extract keys, and place it in either:

  • one big file
  • one file pre each JS files

Code splitting

CRA supports code splitting out of the box 👍, I would also like to split i18n the same way as JS splitted:

Loadable.Map({
  loader: {
    Bar: () => import(/* webpackChunkName: Bar */ './Bar'),
    i18n: () => fetch(`./i18n/${lang}/bar.json`).then(res => res.json()),
  },
  render(loaded, props) {
    let Bar = loaded.Bar.default;
    let i18n = loaded.i18n;
    return <Bar {...props} i18n={i18n}/>;
  },
});

Bar can contain other components (with static imports and i18n keys), for example Foo. So Bar.xxxx.chunk.js can require i18n keys for Foo and for Bar or it can happen that Foo, will be splitted in common.xxxx.chunk.js.

It would be nice to have Bar.xxxx.chunk.json and common.xxxx.chunk.json with i18n keys so appropriate translation files can be generated.

Obviously CRA should not lock-in users with some exact i18n library, but rather we can look into providing low level APIs so other libraries can reuse it. This idea still miss some details, for example, how i18n would work in development environment and maybe other.

Related tickets:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions