A Simple Guide for react-intl Integration in React
Integrate and automate your translations with react-intl
(6 minute read)
Last updated: May 2026
Prefer a different library?
Which library should I choose? Compare them: react-i18next vs react-intl
1. Create a React app
We'll add English and German to a small React app. React Intl renders the messages, while i18nexus handles AI translation and keeps your team's copy in one place.
This example uses Vite and Node.js 22.13+ or 24 LTS. Skip the creation commands if you already have a browser-rendered React app. React Intl 12 requires React 18+.
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm install react-intl@^122. Let i18nexus handle your translations
Write your copy once. i18nexus stores your source strings, AI translates them into your project languages, and gives your team a place to review the results. The CLI brings those translations into your app.
Already have an i18nexus project?
Use its project API key instead of creating another project with init. Install @i18nexus/cli as a dev dependency, add the key to .env, and run npx i18nexus pull. Follow the CLI guide to add development and build sync. The library, languages, namespaces, and output path must match the imports in this tutorial.
To create a new i18nexus project, run this from your app directory:
npx @i18nexus/cli@latest initFor this example, use these choices:
- Sign in or create an account in the browser opened by the CLI.
- Use
react-intlas your library. Installed libraries are detected automatically. - For a new app, choose that you do not have translation JSON yet. Set English (
en) as the base language and German (de) as an additional language. - Use one namespace:
common. - Accept automatic sync in
package.json. This installs the CLI locally and adds development and build sync scripts.
Already have translation JSON?
The CLI can detect and import it into your new i18nexus project. Keep your existing language codes and namespaces, and adjust the examples below to match.
If you keep a custom translation folder, the CLI includes it in your sync scripts. For manual pulls, include that same path: npx i18nexus pull --path ./your-folder.
When setup finishes, add the project API key printed by the CLI to .env in the app root. Add .env to .gitignore:
.envI18NEXUS_API_KEY="your_project_api_key"Add your first two strings
Open the dashboard link printed by the CLI and add these English strings in the common namespace. The key is what your code uses; the value is what your users read.
welcome: Welcome to my app!greeting:Hello, {name}!
Save each string, then expand its row to see the translations. You can review and edit them in the same place as your source text.
Prefer working with an AI coding assistant? Choose MCP setup during init, then ask your assistant to create these same strings through i18nexus. The MCP guide explains that workflow. The dashboard remains available for you and your team.
Give AI translation a moment to finish, then download the generated JSON before adding the imports in the next step:
npx i18nexus pullYou should now have src/messages/en/common.json and its German equivalent. These are generated files: make future string changes in i18nexus and let the CLI sync them.
3. Connect React Intl
For this small example, import both generated language files. This keeps switching immediate and avoids a separate loading state. Larger apps can load messages per language as needed.
src/App.jsximport {useEffect, useState} from 'react';
import {FormattedMessage, IntlProvider} from 'react-intl';
import en from './messages/en/common.json';
import de from './messages/de/common.json';
const messages = {en, de};
const supportedLocales = ['en', 'de'];
function getInitialLocale() {
try {
const saved = localStorage.getItem('locale');
if (supportedLocales.includes(saved)) return saved;
} catch {}
return navigator.languages
.map(language => language.split('-')[0])
.find(language => supportedLocales.includes(language)) || 'en';
}
export default function App() {
const [locale, setLocale] = useState(getInitialLocale);
useEffect(() => {
document.documentElement.lang = locale;
try { localStorage.setItem('locale', locale); } catch {}
}, [locale]);
return (
<IntlProvider locale={locale} defaultLocale="en" messages={messages[locale]}>
<main>
<h1><FormattedMessage id="welcome" /></h1>
<p><FormattedMessage id="greeting" values={{name: 'Sam'}} /></p>
<select aria-label="Language" value={locale} onChange={event => setLocale(event.target.value)}>
<option value="en">English</option>
<option value="de">Deutsch</option>
</select>
</main>
</IntlProvider>
);
}
The provider supplies the locale and messages to FormattedMessage and useIntl. We start with a saved preference or supported browser language, then save later selections for the next visit.
Keep Vite's src/main.jsx, which already renders App with createRoot. This example is for browser-rendered React; use the dedicated Next.js tutorials for server rendering.
Run npm run dev and try the language switcher. The welcome message and greeting should change together:
Add plurals when you need them
Add an items string to the common namespace with the ICU value below. Its count argument selects the correct form:
{count, plural, one {# item} other {# items}}After syncing, render <FormattedMessage id="items" values={{count: 3}} />. Keep the whole sentence together so translations can use the right word order.
Keep translations in sync
The sync script added by the CLI runs i18nexus listen alongside your app. It pulls on startup and updates the generated JSON when strings or translations change in i18nexus. Refresh the page if your app still shows a cached translation.
For deployment, set I18NEXUS_API_KEY in your build environment and run npm run build. The CLI-added prebuild script pulls the latest JSON before compilation. Install dev dependencies in the build stage so the CLI is available. Updates to bundled translations require a new build.
Keep adding source strings in the dashboard or through the i18nexus MCP. Your team can review and refine the AI translations in the same project. React Intl documentation has the details for larger apps.
Level up your localization
It only takes a few minutes to streamline your translations forever.
Get started