Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Import providers and hooks directly from react-native-intlayer; react-intlayer is no longer needed as a direct dependency"v9.0.025/06/2026
- "Update Solid useIntlayer API usage to direct property access"v8.9.004/05/2026
- "Add init command"v7.5.930/12/2025
- "Initial history"v5.5.1029/06/2025
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Translate your Expo and React Native app | Internationalisation (i18n)
Table of Contents
Why Intlayer over alternatives?
Compared to main solutions like react-native-localize or i18next, Intlayer is a solution that comes with integrated optimisations such as:
Intlayer is optimised to work perfectly with React Native and Expo by offering component-level content scoping, TypeScript support, and all the features needed for scaling internationalisation (i18n) in mobile apps.
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, MCP, and agent skills, to make the developer experience (DX) even smoother for AI agents.
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.
Connecting massive JSON files to components can lead to performance and reactivity issues. Intlayer optimises your content loading at build time.
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.
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%.
Install Dependencies
See Application Template on GitHub.
From your React Native project, install the following packages:
bashCopy codeCopy the code to the clipboard
npx intlayer@canary init --interactive # v9# npx intlayer init # v8the
--interactiveflag is optional. Useintlayer-cli initif you're an AI agent.This command will detect your environment and install the required packages. For example:
bashCopy codeCopy the code to the clipboard
npm install intlayer react-native-intlayerPackages
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 fromreact-intlayer, so you only need this single package in a React Native app.
Create an Intlayer Config
In your project root (or anywhere convenient), create an Intlayer config file. It might look like this:
intlayer.config.tsCopy codeCopy the code to the clipboard
/** * 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.
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 initcommand. To use Intlayer with Metro, you need to add the plugin to yourmetro.config.jsfile:metro.config.jsCopy codeCopy the code to the clipboard
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:
configMetroIntlayeris a promise function. UseconfigMetroIntlayerSyncinstead if you want to use it synchronously, or avoid IFFE (Immediately Invoked Function Expression). Note:configMetroIntlayerSyncdoes not allow building intlayer dictionaries on server start.Add the Intlayer provider
To keep the user language synchronised across your application, you need to wrap your root component with the
IntlayerProvidercomponent fromreact-native-intlayer.Always import from
react-native-intlayer. ItsIntlayerProviderincludes polyfills for the web API used by Intlayer, and the package re-exports all the hooks and utilities fromreact-intlayer.Also, you need to add the
intlayerPolyfillfunction to yourindex.jsfile to ensure that Intlayer can work properly.app/_layout.tsxCopy codeCopy the code to the clipboard
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;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.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.
Expo Router (web): keep
.content.*files out of theapp/directory. Expo Router treats every JavaScript/TypeScript file insideapp/as a route. On web, its route discovery scans the filesystem directly and does not honour Metro'sresolver.blockList, so a co-located*.content.tsis registered as a route. A file such asapp/(tabs)/_layout.content.tsis even parsed as a layout (the.contentpart is read as a platform suffix), which collides with the real_layout.tsxand throws:plaintextCopy codeCopy the code to the clipboard
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 examplecontent/orsrc/content/). Intlayer discovers.content.*files anywhere in the project and dictionaries are referenced by theirkey, so no import changes are needed. On native this is not required (Metro'sblockListalready hides them), but using a non-app/directory keeps both platforms working.Example (TypeScript with TSX nodes for React Native):
src/app.content.tsxCopy codeCopy the code to the clipboard
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-GB": "Welcome!", en: "Welcome!", fr: "Bienvenue!", es: "¡Bienvenido!", }), }, } satisfies Dictionary; export default homeScreenContent;For details on content declarations, see Intlayer's content docs.
Use Intlayer in Your Components
Use the
useIntlayerhook in child components to obtain localised content.Example
app/(tabs)/index.tsxCopy codeCopy the code to the clipboard
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: "centre", gap: 8, }, }); export default HomeScreen;When using
content.someKeyin string-based props (e.g., a button'stitleor aTextcomponent'schildren), callcontent.someKey.valueto obtain 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.
Change the App Locale
OptionalTo switch locales from within your components, you can use the
useLocalehook'ssetLocalemethod:src/components/LocaleSwitcher.tsxCopy codeCopy the code to the clipboard
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", colour: "#333", }, });This triggers a re-render of all components that use Intlayer content, now showing translations for the new locale.
See
useLocaledocs 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:
Copy the code to the clipboard
// 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 enables features such as:
- Autocompletion for your dictionary keys.
- Type checking that warns if you access a non-existent key or have a type mismatch.
Git Configuration
To prevent committing auto-generated files by Intlayer, add the following to your .gitignore:
Copy the code to the clipboard
# Ignore the files generated by Intlayer.intlayerVS Code Extension
To enhance your development experience with Intlayer, you can install the official Intlayer VS Code Extension.
Install from the VS Code Marketplace
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.
Go Further
- Visual Editor: Use the Intlayer Visual Editor to manage translations visually.
- CMS Integration: You can also externalise and fetch your dictionary content from a CMS.
- CLI Commands: Explore the Intlayer CLI for tasks like extracting translations or checking missing keys.
Enjoy building your React Native apps with fully powered i18n through Intlayer!
Debug
React Native can be less stable than React Web, so pay extra attention to version alignment.
Intlayer primarily targets the Web Intl API; on React Native you must include the appropriate polyfills.
Checklist:
- Use the latest versions of
intlayerandreact-native-intlayer. - Enable the Intlayer polyfill.
- If you use
getLocaleNameor other Intl-API-based utilities, import these polyfills early (for example inindex.jsorApp.tsx):
Copy the code to the clipboard
import "intl";import "@formatjs/intl-getcanonicallocales/polyfill";import "@formatjs/intl-locale/polyfill";import "@formatjs/intl-pluralrules/polyfill";import "@formatjs/intl-displaynames/polyfill";import "@formatjs/intl-listformat/polyfill";import "@formatjs/intl-numberformat/polyfill";import "@formatjs/intl-relativetimeformat/polyfill";import "@formatjs/intl-datetimeformat/polyfill";- Verify your Metro configuration (resolver aliases, asset plugins,
tsconfigpaths) if modules fail to resolve.