Localization & Translation
DashLearn features resilient multi-language support built using GetX Translations. The project structure uses Mixins and Part files to keep the translation logic clean and modular.
Supported Languages
Section titled “Supported Languages”The app currently supports 10 languages out of the box:
- English (
en_US) - Bangla (
bn_BD) - Arabic (
ar_SA) - German (
de_DE) - Spanish (
es_ES) - French (
fr_FR) - Hindi (
hi_IN) - Italian (
it_IT) - Portuguese (
pt_BR) - Turkish (
tr_TR)
Directory Structure
Section titled “Directory Structure”Translations are located in lib/app/translations/.
app_translations.dart: The main entry point that aggregates all languages._en.dart,_es.dart, etc.: Individual language files defined as parts.
Adding a New Language
Section titled “Adding a New Language”To add a new language (e.g., Japanese ja_JP), follow these steps:
1. Create the Language File
Section titled “1. Create the Language File”Create a new file lib/app/translations/_ja.dart. Define a mixin that implements your translations:
part of 'app_translations.dart';
mixin JaKeys on Translations { final jaKeys = <String, String>{ 'language': '言語', 'details': '詳細', // ... add all required keys };}2. Register in app_translations.dart
Section titled “2. Register in app_translations.dart”Open lib/app/translations/app_translations.dart and register your new mixin.
-
Add Part Directive:
part '_tr.dart';part '_ja.dart'; // Add this -
Add Mixin:
class AppTranslations extends Translationswith EnKeys, ..., TrKeys, JaKeys { // Add JaKeys -
Add to Keys Map:
@overrideMap<String, Map<String, String>> get keys => {'en_US': enKeys,'ja_JP': jaKeys, // Register specific locale};
Changing the Default Locale
Section titled “Changing the Default Locale”To change the app’s default language (fallback), update your GetMaterialApp configuration in main.dart or app_pages.dart (wherever initialized):
GetMaterialApp( // ... locale: Locale('ja', 'JP'), fallbackLocale: Locale('en', 'US'),);