Adding Languages
How to add support for new languages
Adding New Languages
This guide explains how to add support for new languages to your application using the internationalization package.
Overview
The internationalization package currently supports English (en), Turkish (tr), Spanish (es), and German (de). You can add support for additional languages by following these steps:
- Update configuration files
- Create translation files
- Test the new language
Step 1: Update Configuration Files
First, you need to update the configuration files to include the new language:
Update languine.json
Add the new language code to the targets
array in languine.json
:
Update i18nConfig.ts
Add the new language code to the locales
array in i18nConfig.ts
:
Step 2: Create Translation Files
You need to create translation files for the new language in both the dictionaries
and locales
directories:
Create Dictionary File
Create a new file in the dictionaries
directory with the name of your language code:
Then, copy the structure from the English dictionary file and translate the content:
Start by translating the most important sections first, such as navigation, common buttons, and main page content. You can gradually translate the rest of the content over time.
Create Locale File
Create a new file in the locales
directory with the name of your language code:
Then, add the basic translations:
Step 3: Generate Translations (Optional)
If you have a large number of translations, you can use the built-in translation script to generate translations automatically:
This will use the Languine tool to generate translations for all target languages based on the source language (English).
Automatically generated translations may not be perfect. Always review and edit them for accuracy and cultural appropriateness.
Step 4: Test the New Language
After adding the new language, test it to make sure everything works correctly:
-
Start your development server:
-
Visit your application with the new locale path:
-
Check that the content is displayed in the new language.
-
Test navigation, forms, and other interactive elements to ensure translations are applied correctly.
Handling Special Characters and RTL Languages
Special Characters
Some languages use special characters that may require specific handling:
Right-to-Left (RTL) Languages
For languages that are read from right to left (like Arabic or Hebrew), you need to add additional support:
- Create a helper function to identify RTL languages:
- Update your layout to apply RTL direction when needed:
- Add CSS to handle RTL styling:
Best Practices for Multilingual Content
Examples
Adding French Language Support
Here’s a complete example of adding French language support:
- Update
languine.json
:
- Update
i18nConfig.ts
:
- Create
dictionaries/fr.json
with translated content:
- Create
locales/fr.json
:
- Update your language switcher to include French: