React Native Localize Toolbox

3.7.0 · active · verified Sun Apr 19

react-native-localize is a comprehensive toolkit designed to streamline localization within React Native applications, including robust support for Android, iOS, macOS, and Web platforms via react-native-web. The current stable version is 3.7.0. The library's release cadence closely follows React Native's own support policy, focusing on compatibility with the latest version and the two previous minor series. Key differentiators include its broad cross-platform compatibility, an official Expo config plugin (introduced in 3.5.0 and actively refined), and recent additions like server-side rendering (SSR) support in version 3.6.0. It provides essential utilities for accessing device locale information, currency symbols, and managing right-to-left (RTL) layouts, integrating seamlessly into existing React Native projects. The library ships with TypeScript types for enhanced developer experience.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to fetch and display various localization information from the device, including current locales, best available language, country, currencies, timezone, and RTL status, with a listener for locale changes. This is a runnable React Native component.

import React, { useEffect, useState } from 'react';
import { Text, View, StyleSheet, Platform } from 'react-native';
import {
  getLocales,
  getCurrencies,
  getTimezone,
  getCountry,
  findBestAvailableLanguage,
  isRTL,
  addEventListener,
  removeEventListener,
  type Locale,
} from 'react-native-localize';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
    padding: 20,
  },
  title: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  info: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

export default function App() {
  const [currentLocales, setCurrentLocales] = useState<Locale[]>(getLocales());

  useEffect(() => {
    const handleLocalesChange = () => {
      setCurrentLocales(getLocales());
    };
    addEventListener('change', handleLocalesChange);
    return () => removeEventListener('change', handleLocalesChange);
  }, []);

  const bestLanguage = findBestAvailableLanguage(['en', 'fr', 'es']);
  const isCurrentLocaleRTL = isRTL();

  return (
    <View style={styles.container}>
      <Text style={styles.title}>
        React Native Localize Example
      </Text>
      <Text style={styles.info}>
        Current Platform: {Platform.OS}
      </Text>
      <Text style={styles.info}>
        Device Locales: {currentLocales.map(l => l.languageTag).join(', ')}
      </Text>
      <Text style={styles.info}>
        Preferred Language (from ['en', 'fr', 'es']): {bestLanguage?.languageTag ?? 'N/A'}
      </Text>
      <Text style={styles.info}>
        Device Country: {getCountry()}
      </Text>
      <Text style={styles.info}>
        Device Currencies: {getCurrencies().join(', ')}
      </Text>
      <Text style={styles.info}>
        Device Timezone: {getTimezone()}
      </Text>
      <Text style={styles.info}>
        Is Right-to-Left (RTL): {isCurrentLocaleRTL ? 'Yes' : 'No'}
      </Text>
    </View>
  );
}

view raw JSON →