Caracal Starter
Guides

Internationalization

How to add internationalization to your app.

Caracal ships with a basic internationalization (i18n) setup using i18next. Everything i18n-related lives in src/lib/i18n/.

Adding a New Language

The demo app supports English and Vietnamese out of the box. To add another language:

  1. Create a new translation JSON file in src/translations/.
  2. Register it in src/lib/i18n/resources.ts.
src/lib/i18n/resources.ts
import en from '@/translations/en.json';
import vi from '@/translations/vi.json';
// import fr from '@/translations/fr.json';

export const resources = {
  en: { translation: en },
  vi: { translation: vi },
  // fr: { translation: fr },
};

Anything related to internationalization lives in src/lib/i18n/.

Using Translations in Your App

useTranslation hook

Use the useTranslation hook from react-i18next to get the t translation function:

import React from 'react';
import { useTranslation } from 'react-i18next';
import { Text } from '@/components/ui';

export const Foo = () => {
  const { t } = useTranslation();
  return <Text className="text-center">{t('settings.language')}</Text>;
};

Changing the language

useSelectedLanguage() returns { language, setLanguage }. Call setLanguage('vi') or setLanguage('en') to switch immediately and persist the choice in MMKV. On first launch the fallback is English. When adding a language, update the language controls in src/components/auth/language-pill.tsx and src/components/settings/general-section.tsx as well as the resources.

Robust Translations

TypeScript Support

Caracal adds TypeScript definitions for translation keys, giving you autocomplete and compile-time errors when you use an incorrect key. If you reference a key that doesn't exist in the translation files, TypeScript will flag it immediately.

ESLint Rules

Caracal enforces translation file consistency via eslint-plugin-i18n-json and a custom i18next validation script. These rules run as a pre-commit hook whenever translation files change.

The checks enforce:

  • All resource files have identical keys (no missing translations)
  • Keys are sorted consistently
  • JSON syntax is valid

On this page