---
createdAt: 2025-03-09
updatedAt: 2026-09-27
priority: 3
title: "Lynx + React i18n - Complete guide to translate your app"
description: "Set up Intlayer in a Lynx and React mobile app: typed per-component content, device locale detection and a locale switcher."
keywords:
- Internationalization
- Documentation
- Intlayer
- Vite
- React
- Lynx
- JavaScript
slugs:
- doc
- environment
- lynx-and-react
applicationTemplate: https://github.com/aymericzip/intlayer-lynx-template
history:
- version: 8.9.0
date: 2026-05-04
changes: "Update Solid useIntlayer API usage to direct property access"
- version: 7.5.9
date: 2025-12-30
changes: "Add init command"
- version: 5.5.10
date: 2025-06-29
changes: "Initial history"
author: aymericzip
---
# Translate your Lynx and React mobile app website using Intlayer
See [Application Template](https://github.com/aymericzip/intlayer-lynx-template) on GitHub.
## Why Intlayer over alternatives?
Compared to main solutions like `react-native-localize` or `i18next`, Intlayer is a solution that comes with integrated optimizations such as:
Intlayer is optimized to work perfectly with Lynx and React by offering **component-level content scoping**, **TypeScript support**, and all the features needed for scaling internationalization (i18n).
Instead of loading massive JSON files into your pages, load only the necessary content. Intlayer helps **reduce your bundle and page sizes by up to 50%**.
Scoping your application's content **facilitates maintenance** for large-scale applications. You can duplicate or delete a single feature folder without the mental burden of reviewing your entire content codebase. Additionally, Intlayer is **fully typed** to ensure your content's accuracy.
Co-locating content **reduces the context needed** by Large Language Models (LLMs). Intlayer also comes with a suite of tools, such as a **CLI** to test for missing translations,**[LSP](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/lsp.md)**, **[MCP](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md)**, and **[agent skills](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/agent_skills.md)**, to make the developer experience (DX) even smoother for AI agents.
- [LSP](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/lsp.md)
- [MCP](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md)
- [agent skills](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/agent_skills.md)
Use automation to translate in your CI/CD pipeline using the LLM of your choice at the cost of your AI provider. Intlayer also offers a **compiler** to automate content extraction, as well as a [web platform](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md) to help **translate in the background**.
- [web platform](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md)
Connecting massive JSON files to components can lead to performance and reactivity issues. Intlayer optimizes your content loading at build time.
More than just an i18n solution, Intlayer provides an **self-hosted [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md)** and a **[full CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md)** to help you manage your multilingual content in **real-time**, making collaboration with translators, copywriters, and other team members seamless. Content can be stored locally and/or remotely.
- [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md)
- [full CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md)
From your Lynx project, install the following packages:
```bash packageManager="npm"
npx intlayer init --interactive
```
```bash packageManager="pnpm"
pnpm dlx intlayer init --interactive
```
```bash packageManager="yarn"
yarn dlx intlayer init --interactive
```
```bash packageManager="bun"
bunx intlayer init --interactive
```
> the `--interactive` flag is optional. Use `intlayer-cli init` if you're an AI agent.
> This command will detect your environment and install the required packages. For example:
```bash packageManager="npm"
npm install intlayer react-intlayer lynx-intlayer
```
```bash packageManager="pnpm"
pnpm add intlayer react-intlayer lynx-intlayer
```
```bash packageManager="yarn"
yarn add intlayer react-intlayer lynx-intlayer
```
```bash packageManager="bun"
bun add intlayer react-intlayer lynx-intlayer
```
### Packages
- **intlayer**
The core i18n toolkit for configuration, dictionary content, types generation, and CLI commands.
- **react-intlayer**
React integration that provides the context providers and React hooks you’ll use in Lynx for obtaining and switching locales.
- **lynx-intlayer**
Lynx integration that provides the plugin for integrating Intlayer with the Lynx bundler.
In your project root (or anywhere convenient), create an **Intlayer config** file. It might look like this:
```ts fileName="intlayer.config.ts" codeFormat={["typescript", "esm", "commonjs"]}
import { Locales, type IntlayerConfig } from "intlayer";
const config: IntlayerConfig = {
internationalization: {
locales: [
Locales.ENGLISH,
Locales.FRENCH,
Locales.SPANISH,
// ... Add any other locales you need
],
defaultLocale: Locales.ENGLISH,
},
};
export default config;
```
Within this config, you can:
- Configure your **list of supported locales**.
- Set a **default** locale.
- Later, you may add more advanced options (e.g., logs, custom content directories, etc.).
- See the [Intlayer configuration docs](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md) for more.
To use Intlayer with Lynx, you need to add the plugin to your `lynx.config.ts` file:
```ts fileName="lynx.config.ts"
import { defineConfig } from "@lynx-js/rspeedy";
import { pluginIntlayerLynx } from "lynx-intlayer/plugin";
export default defineConfig({
plugins: [
// ... other plugins
pluginIntlayerLynx(),
],
});
```
To keep synchronized the user language across your application, you need to wrap your root component with the `IntlayerProvider` component from `react-intlayer`.
Also, you need to add the `intlayerPolyfill` function file to ensure that Intlayer can work properly.
```tsx fileName="src/index.tsx"
import { root } from "@lynx-js/react";
import { App } from "./App.js";
import { IntlayerProvider } from "react-intlayer";
import { intlayerPolyfill } from "lynx-intlayer";
intlayerPolyfill();
root.render(
);
if (import.meta.webpackHot) {
import.meta.webpackHot.accept();
}
```
Create **content declaration** files anywhere in your project (commonly within `src/`), using any of the extension formats that Intlayer supports:
- `.content.json`
- `.content.jsonc`
- `.content.json5`
- `.content.ts`
- `.content.tsx`
- `.content.js`
- `.content.jsx`
- `.content.mjs`
- `.content.mjx`
- `.content.cjs`
- `.content.md`
- `.content.mdx`
- `.content.yaml`
- `.content.yml`
- etc.
Example:
```tsx fileName="src/app.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
import { t, type Dictionary } from "intlayer";
const appContent = {
key: "app",
content: {
title: "React",
subtitle: t({
en: "on Lynx",
fr: "sur Lynx",
es: "en Lynx",
}),
description: t({
en: "Tap the logo and have fun!",
fr: "Appuyez sur le logo et amusez-vous!",
es: "¡Toca el logo y diviértete!",
}),
hint: [
t({
en: "Edit",
fr: "Modifier",
es: "Editar",
}),
" src/App.tsx ",
t({
en: "to see updates!",
fr: "pour voir les mises à jour!",
es: "para ver actualizaciones!",
}),
],
},
} satisfies Dictionary;
export default appContent;
```
```json fileName="src/app.content.json" contentDeclarationFormat="json"
{
"$schema": "https://intlayer.org/schema.json",
"key": "app",
"content": {
"title": "React",
"subtitle": {
"nodeType": "translation",
"translation": {
"en": "on Lynx",
"fr": "sur Lynx",
"es": "en Lynx"
}
},
"description": {
"nodeType": "translation",
"translation": {
"en": "Tap the logo and have fun!",
"fr": "Appuyez sur le logo et amusez-vous!",
"es": "¡Toca el logo y diviértete!"
}
},
"hint": [
{
"nodeType": "translation",
"translation": {
"en": "Edit",
"fr": "Modifier",
"es": "Editar"
}
},
" src/App.tsx ",
{
"nodeType": "translation",
"translation": {
"en": "to see updates!",
"fr": "pour voir les mises à jour!",
"es": "para ver actualizaciones!"
}
}
]
}
}
```
> For details on content declarations, see [Intlayer’s content docs](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md).
- [Intlayer’s content docs](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md)
Use the `useIntlayer` hook in child components to get localized content.
```tsx fileName="src/App.tsx"
import { useCallback, useState } from "@lynx-js/react";
import { useIntlayer } from "react-intlayer";
import "./App.css";
import arrow from "./assets/arrow.png";
import lynxLogo from "./assets/lynx-logo.png";
import reactLynxLogo from "./assets/react-logo.png";
import { LocaleSwitcher } from "./components/LocaleSwitcher.jsx";
export const App = () => {
const [alterLogo, setAlterLogo] = useState(false);
const { title, subtitle, description, hint } = useIntlayer("app");
const onTap = useCallback(() => {
"background only";
setAlterLogo(!alterLogo);
}, [alterLogo]);
return (
{alterLogo ? (
) : (
)}
{title}
{subtitle}
{description}
{hint[0]}
{hint[1]}
{hint[2]}
);
};
```
> When using `content.someKey` in string-based props (e.g., a button’s `title` or a `Text` component’s `children`), **call `content.someKey.value`** to get the actual string.
To switch locales from within your components, you can use the `useLocale` hook’s `setLocale` method:
```tsx fileName="src/components/LocaleSwitcher.tsx"
import { type FC } from "react";
import { getLocaleName } from "intlayer";
import { useLocale } from "react-intlayer";
export const LocaleSwitcher: FC = () => {
const { setLocale, availableLocales, locale } = useLocale();
return (
{availableLocales.map((localeEl) => (
setLocale(localeEl)}
>
{getLocaleName(localeEl)}
))}
);
};
```
This triggers a re-render of all components that use Intlayer content, now showing translations for the new locale.
> See [`useLocale` docs](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md) for more details.
- [`useLocale` docs](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md)
## Configure TypeScript (if you use TypeScript)
Intlayer generates type definitions in a hidden folder (by default `.intlayer`) to improve autocompletion and catch translation errors:
```json5
// tsconfig.json
{
// ... your existing TS config
"include": [
"src", // your source code
".intlayer/types/**/*.ts", // <-- ensure the auto-generated types are included
// ... anything else you already include
],
}
```
This is what enables features like:
- **Autocompletion** for your dictionary keys.
- **Type checking** that warns if you access a non-existent key or mismatch the type.
## Git Configuration
To avoid committing auto-generated files by Intlayer, add the following to your `.gitignore`:
```bash
# Ignore the files generated by Intlayer
.intlayer
```
### VS Code Extension
To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
- [Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
This extension provides:
- **Autocompletion** for translation keys.
- **Real-time error detection** for missing translations.
- **Inline previews** of translated content.
- **Quick actions** to easily create and update translations.
For more details on how to use the extension, refer to the [Intlayer VS Code Extension documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/vs_code_extension.md).
- [Intlayer VS Code Extension documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/vs_code_extension.md)
## Go Further
- [Intlayer Visual Editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md)
- [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md)
- [Intlayer CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/cli/index.md)
---