Skip to content
Tutorials Center
My learning

Topics

Lesson 45 of 71 · Native Features

Internationalization: Multi-Language Apps with i18next

Add multiple languages to a React Native app: i18next and react-i18next setup, translation files, fallback language, plurals, interpolation, locale detection and right-to-left layout.

An app that only speaks one language leaves a lot of users behind. Internationalization (often written i18n) is the work of building an app so it can be translated, and localization is the work of providing a particular language. In React Native the usual stack is i18next (the translation engine), react-i18next (the React bindings) and expo-localization (to read the language of the device). This lesson shows how they fit together, how to handle plurals and dynamic values, and what changes for right-to-left languages.

What runs on this site. The npm packages are not available in the in-browser runner, so the real code with i18next is read-only. The runnable example is a stand-in: a tiny translation function with the same ideas (resources, a fallback language, interpolation, plurals via Intl.PluralRules, changeLanguage) so you see how the library behaves.

The pieces

The i18n stack

i18next Looks up the right string.
react-i18next Re-renders when language changes.
expo-localization Reads the device language.

Three small packages, one job each.

1 / 2

Install and create the translation files

Terminal
npx expo install expo-localization
npm install i18next react-i18next

Keep the translations in plain JSON-like objects, one per language, using keys that describe the meaning (home.greeting) rather than the English text. Keys are stable when the wording changes.

JavaScript
// i18n/en.js
export default {
  welcome: 'Welcome',
  greeting: 'Hello, {{name}}!',
  cart_one: 'You have {{count}} item',
  cart_other: 'You have {{count}} items',
  settings: { language: 'Language' },
};

// i18n/hi.js
export default {
  welcome: 'स्वागत है',
  greeting: 'नमस्ते, {{name}}!',
  cart_one: 'आपके पास {{count}} वस्तु है',
  cart_other: 'आपके पास {{count}} वस्तुएँ हैं',
  settings: { language: 'भाषा' },
};

Two syntax points. {{name}} is interpolation: i18next replaces it with the value you pass. And the _one and _other suffixes are plural forms: when you call t('cart', { count: 3 }), i18next picks the right form with the language's plural rules.

Initialise i18next once

JavaScript
// i18n/index.js
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import { getLocales } from 'expo-localization';
import en from './en';
import hi from './hi';

const deviceLanguage = getLocales()[0]?.languageCode ?? 'en';

i18n
  .use(initReactI18next)          // connect to React
  .init({
    resources: {
      en: { translation: en },
      hi: { translation: hi },
    },
    lng: deviceLanguage,          // start in the device language
    fallbackLng: 'en',            // used for any key the language lacks
    interpolation: { escapeValue: false }, // React already escapes
  });

export default i18n;

Import this file once at the top of your entry file (import './i18n';) so it runs before any screen. fallbackLng is the safety net: if Hindi lacks a key, the English text shows instead of the raw key. escapeValue: false is correct for React Native, because the framework does not interpret strings as HTML.

Using translations in components

JSX
import { View, Text, Button } from 'react-native';
import { useTranslation } from 'react-i18next';

export function Home() {
  const { t, i18n } = useTranslation();
  const items = 3;

  return (
    <View style={{ padding: 16, gap: 8 }}>
      <Text style={{ fontSize: 24 }}>{t('welcome')}</Text>
      <Text>{t('greeting', { name: 'Ada' })}</Text>
      <Text>{t('cart', { count: items })}</Text>
      <Text>{t('settings.language')}: {i18n.language}</Text>
      <Button title="English" onPress={() => i18n.changeLanguage('en')} />
      <Button title="हिन्दी" onPress={() => i18n.changeLanguage('hi')} />
    </View>
  );
}

useTranslation gives you t (the lookup function) and i18n (the instance). When changeLanguage runs, every component that used the hook re-renders with the new strings, with no extra state in your code. t('settings.language') uses a dot to reach into a nested object.

Remember the user's choice

Detecting the device language is a good default, but a user who picks a language expects it to stick. Save it with AsyncStorage (see Storing Data) when it changes, and read it before calling init, so the first screen is already in the right language:

JavaScript
const saved = await AsyncStorage.getItem('language');
i18n.init({ lng: saved ?? deviceLanguage, /* ... */ });

// when the user chooses:
await i18n.changeLanguage(code);
await AsyncStorage.setItem('language', code);

Plurals are not just one and many

English has two plural forms, but Russian has three forms, Arabic has six, and Japanese has one. That is why you must not write count === 1 ? 'item' : 'items' yourself. Modern JavaScript exposes the rules through Intl.PluralRules, which i18next uses. Provide the suffixes your language needs (_zero, _one, _two, _few, _many, _other) and let the library choose.

Numbers, dates and currency

Translate text with i18next, and format values with Intl: new Intl.NumberFormat(lang, { style: 'currency', currency: 'EUR' }).format(1234.5) and new Intl.DateTimeFormat(lang, { dateStyle: 'long' }).format(date). They produce 1.234,50 € in German and €1,234.50 in English without a single translation key. Hermes supports Intl on current React Native.

Right-to-left languages

Arabic, Hebrew and Persian are written right to left. React Native flips layouts automatically when the app is in RTL mode: flexDirection: 'row' runs right to left, and marginStart and paddingEnd follow the reading direction. For that to work:

  • Use logical style names, marginStart and marginEnd (and start and end for positions), instead of marginLeft and marginRight, wherever the side depends on reading direction.
  • Enable it with I18nManager.allowRTL(true) and, when the language changes between directions, I18nManager.forceRTL(isRtl). The change takes effect after the app restarts (use Updates.reloadAsync() from expo-updates).
  • Mirror direction-bearing icons (arrows, chevrons) but not logos or media controls.

Testing and process tips

  • Add the translation files to your review process. Missing keys appear as the key text on screen (settings.language), so scan for dots in the UI.
  • Test with a long language (German) and an RTL language: buttons that fit "Save" may not fit "Speichern".
  • Never build sentences by joining pieces (t('you_have') + count + t('items')). Word order differs by language; give translators the whole sentence with placeholders.
  • Keep all user-facing strings out of components. A literal <Text>Save</Text> is a future bug.
A mini i18n engine: fallback, interpolation and plurals

Choose Russian and change the count to 1, 2, 5 and 21: the forms follow the language's plural rules (one, few, many, one), which is exactly what a hand-written count === 1 check cannot do.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. What does fallbackLng do?

    When a key is missing for the active language, i18next looks in the fallback language, so users see English text rather than a raw key.
  2. 2. Why should you avoid writing count === 1 ? 'item' : 'items' yourself?

    Plural rules differ widely. Using the _one, _few, _many and _other keys with t('key', { count }) delegates the choice to the language rules.
  3. 3. Which style property names should you prefer so layouts mirror correctly in RTL?

    marginStart and marginEnd follow the reading direction and flip in RTL, while left and right are fixed.
  4. 4. When must the saved language be read?

    Reading the saved choice first avoids a flash of the wrong language.

Summary

  • Use i18next, react-i18next and expo-localization: keys in translation files, useTranslation in components, changeLanguage to switch.
  • Keys describe meaning; {{name}} interpolates values; _one, _other (and more) suffixes handle plurals.
  • Set fallbackLng so missing translations fall back to a default language, and remember the user's choice before init.
  • Format numbers, dates and currency with Intl, not translation keys; never join sentence fragments.
  • For RTL, use marginStart and marginEnd, call I18nManager.forceRTL, and restart the app.

Next: Native Modules, Expo Modules and Config Plugins.