Configuring Translations
The app uses easy_localization for managing multiple languages. Translations are stored in JSON files under the assets/translations directory.
Adding/Modifying Translations
- Navigate to
assets/translations/ - Each language has its own JSON file (e.g.,
en.json,vi.json,ar.json) - Update or add new translations in the format:json
{ "key": "translated text", "nested": { "key": "nested translated text" } }
Supported Languages
The app currently supports:
- English (en)
- Vietnamese (vi)
- Arabic (ar)
- Bengali (bn)
- Spanish (es)
- French (fr)
- Hindi (hi)
- Indonesian (id)
Adding a New Language
- Create a new JSON file in
assets/translations/(e.g.,fr.jsonfor French) - Add the new locale in
lib/main.dart:dartsupportedLocales: const [ Locale('en'), Locale('vi'), Locale('ar'), // Add your new locale here Locale('fr'), ],
Using Translations in Code
Import the translation package:
dartimport 'package:easy_localization/easy_localization.dart';Use translations in your code:
dart// Simple translation Text('hello'.tr()) // Translation with parameters Text('welcome_user'.tr(args: ['John'])) // Pluralization Text('items_count'.plural(5))
Important Notes
- Always use meaningful keys for translations
- Keep translations organized in nested objects for better structure
- Test all supported languages after making changes
- Consider RTL (Right-to-Left) support for languages like Arabic
- Keep translation files in sync across all languages
