Translate your Expo and React Native app | Internationalization (i18n)
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:
Full React Native coverage
Intlayer is optimized to work perfectly with React Native and Expo by offering component-level content scoping, TypeScript support, and all the features needed for scaling internationalization (i18n) in mobile apps.
Maintainability
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.
AI Agent
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, MCP, and agent skills, to make the developer experience (DX) even smoother for AI agents.
Automation
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 to help translate in the background.
Performance
Connecting massive JSON files to components can lead to performance and reactivity issues. Intlayer optimizes your content loading at build time.
Scaling with none-dev
More than just an i18n solution, Intlayer provides an self-hosted visual editor and a full CMS 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.
Bundle size
Instead of loading massive JSON files into your pages, load only the necessary content. Intlayer helps reduce your bundle and view sizes by up to 50%.
1 - Install Dependencies
See Application Template on GitHub.
From your React Native project, install the following packages:
npx intlayer-cli init --interactive
pnpm dlx intlayer-cli init --interactive
yarn dlx intlayer-cli init --interactive
bunx intlayer-cli 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:
npm install intlayer react-native-intlayer
pnpm add intlayer react-native-intlayer
yarn add intlayer react-native-intlayer
bun add intlayer react-native-intlayer
Packages
intlayer
The core i18n toolkit for configuration, dictionary content, types generation, and CLI commands.
react-native-intlayer
React Native integration that provides the context providers and React hooks you'll use to obtain and switch locales, the React Native polyfills, and the Metro plugin for integrating Intlayer with the React Native bundler. It re-exports everything from react-intlayer, so you only need this single package in a React Native app.
2 - Create an Intlayer Config
In your project root (or anywhere convenient), create an Intlayer config file. It might look like this:
/**
* If Locales types is not available, try to set moduleResolution to "bundler" in your tsconfig.json
*/
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 for more.
3 - Add the Metro plugin
Metro is a bundler for React Native. It is the default bundler for React Native projects created with the react-native init command. To use Intlayer with Metro, you need to add the plugin to your metro.config.js file:
const { getDefaultConfig } = require("expo/metro-config");
const { configMetroIntlayer } = require("react-native-intlayer/metro");
module.exports = (async () => {
const defaultConfig = getDefaultConfig(__dirname);
return await configMetroIntlayer(defaultConfig);
})();
Note: configMetroIntlayer is a promise function. Use configMetroIntlayerSync instead if you want to use it synchronously, or avoid IFFE (Immediately Invoked Function Expression).
Note: configMetroIntlayerSync does not allow to build intlayer dictionaries on server start
4 - Add the Intlayer provider
To keep synchronized the user language across your application, you need to wrap your root component with the IntlayerProvider component from react-native-intlayer.
Always import from react-native-intlayer. Its IntlayerProvider includes polyfills for the web API used by Intlayer, and the package re-exports all the hooks and utilities from react-intlayer.
Also, you need to add the intlayerPolyfill function to your index.js file to ensure that Intlayer can work properly.
import { Stack } from "expo-router";
import { getLocales } from "expo-localization";
import { IntlayerProvider } from "react-native-intlayer";
import { type FC } from "react";
const getDeviceLocale = () => getLocales()[0]?.languageTag;
const RootLayout: FC = () => {
return (
<IntlayerProvider defaultLocale={getDeviceLocale()}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
</Stack>
</IntlayerProvider>
);
};
export default RootLayout;
5 - Declare Your Content
Create content declaration files anywhere in your project (commonly within src/), using any of the extension formats that Intlayer supports:
.content.json
.content.ts
.content.tsx
.content.js
.content.jsx
.content.mjs
.content.mjx
.content.cjs
.content.cjx
- etc.
Expo Router (web): keep .content.* files out of the app/ directory. Expo Router treats every JavaScript/TypeScript file inside app/ as a route. On web, its route discovery scans the filesystem directly and does not honor Metro's resolver.blockList, so a co-located *.content.ts is registered as a route. A file such as app/(tabs)/_layout.content.ts is even parsed as a layout (the .content part is read as a platform suffix), which collides with the real _layout.tsx and throws:
The layouts "./(tabs)/_layout.content.ts" and "./(tabs)/_layout.tsx" conflict on the route "/(tabs)/_layout.content". Remove or rename one of these files.
Place your declarations in a directory outside app/ (for example content/ or src/content/). Intlayer discovers .content.* files anywhere in the project and dictionaries are referenced by their key, so no import changes are needed. On native this is not required (Metro's blockList already hides them), but using a non-app/ directory keeps both platforms working.
Example (TypeScript with TSX nodes for React Native):
import { t, type Dictionary } from "intlayer";
import type { ReactNode } from "react";
/**
* Content dictionary for our "app" domain
*/
import { t, type Dictionary } from "intlayer";
const homeScreenContent = {
key: "home-screen",
content: {
title: t({
en: "Welcome!",
fr: "Bienvenue!",
es: "¡Bienvenido!",
}),
},
} satisfies Dictionary;
export default homeScreenContent;
{
"$schema": "https://intlayer.org/schema.json",
"key": "app",
"content": {
"title": {
"nodeType": "translation",
"translation": {
"en": "Welcome!",
"fr": "Bienvenue!",
"es": "¡Bienvenido!"
}
}
}
}
For details on content declarations, see Intlayer’s content docs.
6 - Use Intlayer in Your Components
Use the useIntlayer hook in child components to get localized content.
Example
import { Image, StyleSheet, Platform } from "react-native";
import { useIntlayer } from "react-native-intlayer";
import { HelloWave } from "@/components/HelloWave";
import ParallaxScrollView from "@/components/ParallaxScrollView";
import { ThemedText } from "@/components/ThemedText";
import { ThemedView } from "@/components/ThemedView";
import { type FC } from "react";
const HomeScreen = (): FC => {
const { title, steps } = useIntlayer("home-screen");
return (
<ParallaxScrollView
headerBackgroundColor={{ light: "#A1CEDC", dark: "#1D3D47" }}
headerImage={
<Image
source={require("@/assets/images/partial-react-logo.png")}
style={styles.reactLogo}
/>
}
>
<ThemedView style={styles.titleContainer}>
<ThemedText type="title">{title}</ThemedText>
<HelloWave />
</ThemedView>
</ParallaxScrollView>
);
};
const styles = StyleSheet.create({
titleContainer: {
flexDirection: "row",
alignItems: "center",
gap: 8,
},
});
export default HomeScreen;
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.
If your app already exists, you can use the Intlayer Compiler, as well as the extract command, to transform thousands of components in a second.
7 - Change the App Locale
To switch locales from within your components, you can use the useLocale hook’s setLocale method:
import { type FC } from "react";
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
import { getLocaleName } from "intlayer";
import { useLocale } from "react-native-intlayer";
export const LocaleSwitcher: FC = () => {
const { setLocale, availableLocales } = useLocale();
return (
<View style={styles.container}>
{availableLocales.map((locale) => (
<TouchableOpacity
key={locale}
style={styles.button}
onPress={() => setLocale(locale)}
>
<Text style={styles.text}>{getLocaleName(locale)}</Text>
</TouchableOpacity>
))}
</View>
);
};
const styles = StyleSheet.create({
container: {
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
gap: 8,
},
button: {
paddingVertical: 6,
paddingHorizontal: 12,
borderRadius: 6,
backgroundColor: "#ddd",
},
text: {
fontSize: 14,
fontWeight: "500",
color: "#333",
},
});
This triggers a re-render of all components that use Intlayer content, now showing translations for the new locale.
See useLocale docs for more details.
Configure TypeScript (if you use TypeScript)
Intlayer generates type definitions in a hidden folder (by default .intlayer) to improve autocompletion and catch translation errors:
// 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:
# 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.