This project shows how to use the Rspack JavaScript bundler with Lingui JS to provide i18n for a React application (TypeScript).
npm installto install dependenciesnpm run devto run the development server.npm run buildto build the application.
- Wrap any messages requiring translation in
<Trans>or a related macro. npm run extractto generate message catalogs insrc/locales/{locale}/messages.- Translate any new messages in the catalogs.
- Restart the dev server or rebuild the app.
@lingui/loadercompiles.pocatalogs during bundling, so no separatelingui compilestep is required.
-
rspack.config.jsconfigures both thebuiltin:swc-loaderand@lingui/loader. The SWC plugin transpiles Lingui Macros like<Trans>into their React runtime equivalents, while@lingui/loaderturns imported.pocatalogs into runtime messages at build time. When using Lingui SWC plugin, ensure version compatibility with@rspack/core. Refer to the compatibility guide for selecting the appropriate plugin version. -
src/i18n.tslazy-loads locale catalogs fromsrc/locales/{locale}/messages.po, which letsrspacksplit translations into separate chunks and compile them through@lingui/loader. -
lingui.config.tsspecifies the available locales, defaults, and paths where the message catalogs are stored.
- This blog post shows a step-by-step guide to set up LinguiJS with React.
- Official documentation for React setup with LinguiJS. This repo closely follows the example from the official docs.
