A toolbox for your React Native app localization.
This library follows the React Native releases support policy.
It is supporting the latest version, and the two previous minor series.
$ npm install --save react-native-localize
# --- or ---
$ yarn add react-native-localizeDon't forget to run pod install after that !
List your supported locales under CFBundleLocalizations in ios/YourApp/Info.plist:
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>fr</string>
</array>Set android:localeConfig on the <application> element in android/app/src/main/AndroidManifest.xml:
<applicationandroid:localeConfig="@xml/locale_config" />Then list your supported locales in android/app/src/main/res/xml/locale_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<locale-configxmlns:android="http://schemas.android.com/apk/res/android">
<localeandroid:name="en" />
<localeandroid:name="fr" />
</locale-config>Specify the supported locales in your app.json or app.config.js using the config plugin.
Dynamic configuration (app.config.js, app.config.ts)
importtype{ConfigContext,ExpoConfig}from"expo/config";importlocalizefrom"react-native-localize/expo";// use `require` in app.config.jsexportdefault({ config }: ConfigContext): ExpoConfig=>({plugins: [localize({locales: ["en","fr"],// or { android: ["en"], ios: ["en", "fr"] }}),],});Static configuration (app.json)
import{getCurrencies,getLocales}from"react-native-localize";console.log(getLocales());console.log(getCurrencies());Returns the user preferred calendar format.
typegetCalendar=()=>|"gregorian"|"buddhist"|"coptic"|"ethiopic"|"ethiopic-amete-alem"|"hebrew"|"indian"|"islamic"|"islamic-umm-al-qura"|"islamic-civil"|"islamic-tabular"|"iso8601"|"japanese"|"persian";import{getCalendar}from"react-native-localize";console.log(getCalendar());// -> "gregorian"Returns the user current country code (based on its device locale, not on its position).
typegetCountry=()=>string;import{getCountry}from"react-native-localize";console.log(getCountry());// -> "FR"Devices using Latin American regional settings will return "UN" instead of "419", as the latter is not a standard country code.
Returns the user preferred currency codes, in order.
typegetCurrencies=()=>string[];import{getCurrencies}from"react-native-localize";console.log(getCurrencies());// -> ["EUR", "GBP", "USD"]Returns the user preferred locales, in order.
typegetLocales=()=>Array<{languageCode: string;scriptCode?: string;countryCode: string;languageTag: string;isRTL: boolean;}>;import{getLocales}from"react-native-localize";console.log(getLocales());/* -> [ { countryCode: "GB", languageTag: "en-GB", languageCode: "en", isRTL: false }, { countryCode: "US", languageTag: "en-US", languageCode: "en", isRTL: false }, { countryCode: "FR", languageTag: "fr-FR", languageCode: "fr", isRTL: false },] */Returns number formatting settings.
typegetNumberFormatSettings=()=>{decimalSeparator: string;groupingSeparator: string;};import{getNumberFormatSettings}from"react-native-localize";console.log(getNumberFormatSettings());/* -> { decimalSeparator: ".", groupingSeparator: ",",} */Returns the user preferred temperature unit.
typegetTemperatureUnit=()=>"celsius"|"fahrenheit";import{getTemperatureUnit}from"react-native-localize";console.log(getTemperatureUnit());// -> "celsius"Returns the user preferred timezone (based on its device settings, not on its position).
typegetTimeZone=()=>string;import{getTimeZone}from"react-native-localize";console.log(getTimeZone());// -> "Europe/Paris"Returns true if the user prefers 24h clock format, false if they prefer 12h clock format.
typeuses24HourClock=()=>boolean;import{uses24HourClock}from"react-native-localize";console.log(uses24HourClock());// -> trueReturns true if the user prefers metric measure system, false if they prefer imperial.
typeusesMetricSystem=()=>boolean;import{usesMetricSystem}from"react-native-localize";console.log(usesMetricSystem());// -> trueTells if the automatic date & time setting is enabled on the phone. Android only
typeusesAutoDateAndTime=()=>boolean|undefined;import{usesAutoDateAndTime}from"react-native-localize";console.log(usesAutoDateAndTime());// true or falseTells if the automatic time zone setting is enabled on the phone. Android only
typeusesAutoTimeZone=()=>boolean|undefined;import{usesAutoTimeZone}from"react-native-localize";console.log(usesAutoTimeZone());Returns the best language tag possible and its reading direction. Useful to pick the best translation available.
Note
It respects the user preferred languages list order (see explanations).
typefindBestLanguageTag=(languageTags: string[],)=>{languageTag: string;isRTL: boolean}|undefined;import{findBestLanguageTag}from"react-native-localize";console.log(findBestLanguageTag(["en-US","en","fr"]));// -> { languageTag: "en-US", isRTL: false }Opens the app language settings.
Warning
This feature is available only on Android 13+ and require configuring your app's supported locales.
typeopenAppLanguageSettings=()=>Promise<void>;import{openAppLanguageSettings}from"react-native-localize";openAppLanguageSettings("application").catch((error)=>{console.warn("Cannot open app language settings",error);});On the client, react-native-localize uses navigator.languages. During SSR, it gets language preferences from the server via the parsed Accept-Language header.
On the server, wrap your app with ServerLanguagesProvider and pass the user's languages:
importacceptsfrom"accepts";import{ServerLanguagesProvider}from"react-native-localize";// parse the Accept-Language header; any approach returning string[] is fineconstlanguages=accepts(request).languages();consthtml=renderToString(<ServerLanguagesProvidervalue={languages}><App/></ServerLanguagesProvider>,);In your components, use the useLocalize hook instead of calling the API methods directly:
import{useLocalize}from"react-native-localize";constApp=()=>{const{ getCountry }=useLocalize();return<Text>Country: {getCountry()}</Text>;};Examples with @formatjs/intl
Browse the files in the /example directory.
Because it's a native module, you need to mock this package.
The package provides a default mock you may import in your __mocks__ directory:
// __mocks__/react-native-localize.tsexport*from"react-native-localize/mock";// or "react-native-localize/mock/jest"This module is provided as is, I work on it in my free time.
If you or your company uses it in a production app, consider sponsoring this project 💰. You also can contact me for premium enterprise support: help with issues, prioritize bugfixes, feature requests, etc.

{ "expo": { "plugins": [ [ "react-native-localize", { "locales": ["en", "fr"], // or { android: ["en"], ios: ["en", "fr"] } }, ], ], }, }