Documentation

Hey friend! We are co-hosting a conference with Software Mansion, learn more.

Localization

You can use this module to Localize your app, and access the locale data on the native device. Using the popular library i18n-js with expo-localization will enable you to create a very accessible experience for users.

import React from 'react';
import { Text } from 'react-native';
import { Localization } from 'expo-localization';
import i18n from 'i18n-js';
const en = {
  foo: 'Foo',
  bar: 'Bar {{someValue}}',
};
const fr = {
  foo: 'como telle fous',
  bar: 'chatouiller {{someValue}}',
};

i18n.fallbacks = true;
i18n.translations = { fr, en };
i18n.locale = Localization.locale;
export default class LitView extends React.Component {
  render() {
    return (
      <Text>
        {i18n.t('foo')} {i18n.t('bar', { someValue: Date.now() })}
      </Text>
    );
  }
}

This API is mostly synchronous and driven by constants. On iOS the constants will always be correct, on Android you should check if the locale has updated using AppState and Expo.Localization.getLocalizationAsync(). Initally the constants will be correct on both platforms, but on Android a user can change the language and return, more on this later.

Native device language, returned in standard format. ex: en-US, es-US.

List of all the native languages provided by the user settings. These are returned in the order the user defines in their native settings.

Country code for your device.

A list of all the supported ISO codes.

The current time zone in display format. ex: America/Los_Angeles

This will return true if the current language is Right-to-Left.

Android only, on iOS changing the locale settings will cause all the apps to reset.
type NativeEvent = {
  locale: string,
  locales: Array<string>,
  timezone: string,
  isoCurrencyCodes: ?Array<string>,
  country: ?string,
  isRTL: boolean,
};
Example
// When the app returns from the background on Android...

const { locale } = await Localization.getLocalizationAsync();