Making Your App Multilingual
The boilerplate includes a ready-to-use internationalization (i18n) system that makes creating multilingual apps simple. This guide will walk you through the process with practical examples.What You’ll Learn
- How to use existing translations
- Adding new text and phrases
- Working with dynamic content (variables)
- Creating a new language
- Building a complete multilingual feature
Simple Translation Examples
Let’s learn how to use translations in your app with a simple Fortune Cookie example.Step 1: Set Up Your Translation Files
1
Find the translation files
Your app already has translation files in:
2
Add translations to English file
Open
lib/i18n/locales/en/common.json
and add:3
Add same translations in French
Open
lib/i18n/locales/fr/common.json
and add:Step 2: Use the Translations in Your Component
Here’s a basic example of using translations:Step 3: Using Variables in Translations
You can also include dynamic content in your translations:1
Add translations with variables
Add to your English file (And to your French file (Notice the
en/common.json
):fr/common.json
):{{name}}
and {{number}}
placeholders.2
Use variables in your component
Here’s how to use these translations with variables:The second parameter to the
t()
function is an object containing your variable values.Adding a New Language
Now let’s add Spanish as a new language option:1
Create language folder and file
2
Translate to new language
Edit
lib/i18n/locales/es/common.json
with Spanish translations:3
Register the new language
Open
lib/i18n/i18n.ts
and update it to include Spanish:4
Add to language selector
Find the language selection component (
components/account/LanguageSettingsSheet.tsx
) and add Spanish:Testing Your Translations
To make sure your translations work correctly:- Open your app and navigate to the language settings (usually in the account/settings section)
- Switch between languages and verify your text appears correctly
- Check that variable substitutions work as expected
Best Practices
- Stay organized: Group translations by feature (“profile”, “settings”, etc.)
- Be consistent: Use the same key naming patterns throughout
- Keep keys in English: Even for translations, keep the key names in English
- Test thoroughly: Test all languages after adding new translations
- Use descriptive keys: Keys like “profile.nameLabel” are self-explanatory