NeoIQ Localize

Expo Preset

The Expo preset helps you set up internationalization (i18n) in your Expo project with minimal configuration. It integrates with Expo's localization system and sets up all necessary files and configurations for managing translations.

Prerequisites

  • An Expo project
  • Git initialized repository
  • Node.js and npm/yarn/pnpm

Getting Started

Navigate to your Expo project root and run:

npx @neoiq/localize@latest init --preset expo

Configure your source and target languages when prompted, or create a neoiq-localize.json file:

neoiq-localize.json
{
  "locale": {
    "source": "en",
    "targets": ["es", "fr"]
  }
}

What Gets Set Up

The preset will:

Install required dependencies:

  • i18n-js - For handling translations
  • expo-localization - For detecting device locale

Create the following directory structure:

i18n.ts
en.json
[lang].json
en.json
[lang].json
README.md

Configure your app.json for localization support:

  • Enables mixed localizations for iOS
  • Adds expo-localization plugin
  • Sets up native localization paths

Usage

Basic Translation

Import the i18n instance in your components:

src/components/MyComponent.tsx
import i18n from './locales/i18n';
 
function Welcome() {
  return <Text>{i18n.t('welcome')}</Text>;
}

Translation Files

The preset creates two types of translation files:

  1. Regular translations (locales/[lang].json):

    locales/[lang].json
    {
      "welcome": "Welcome to my app",
      "hello": "Hello",
      "settings": "Settings"
    }
  2. Native translations (locales/native/[lang].json):

    locales/native/[lang].json
    {
      "CFBundleDisplayName": "My App",
      "NSContactsUsageDescription": "We need access to contacts..."
    }

Managing Translations

Add new translation keys to your source language file (locales/[source].json)

Run the translation command:

npx @neoiq/localize@latest translate

Best Practices

  1. Always use translation keys in your code instead of hardcoded strings
  2. Keep translation keys organized and descriptive
  3. Use the native translations for app store metadata and system permissions
  4. Commit translation files to version control

Troubleshooting

Additional Configuration

The preset supports customization through the neoiq-localize.json file:

neoiq-localize.json
{
  "locale": {
    "source": "en",
    "targets": ["es", "fr"]
  },
  "files": {
    "json": {
      "include": [
        "locales/native/[locale].json",
        "locales/[locale].json"
      ]
    }
  }
}

For more advanced configuration options, refer to the NeoIQ Localize configuration documentation.

How is this guide?

Edit on GitHub

Last updated on