A lightweight and simple dynamic translation loader for Flutter apps using .arb files.
No need for
flutter_localizationsorintl– just pure Dart!
- ✅ Easy to use translation service
- 🗂 Dynamic
.arbfile loader - 🔁 Runtime locale switching
- ❌ No
intlorflutter_localizationsdependency required - 📁 Minimal folder structure
## 📂 Project Structure
flutter-dynamic-translator/
├── lib/
│ └── dynamic_translator.dart # Translation logic
├── assets/
│ └── lang/
│ ├── en.arb
│ ├── mn.arb
│ └── ko.arb
├── pubspec.yaml
└── README.md
Create .arb files under assets/lang/:
// en.arb
{
"hello_world": "Hello, World!",
"welcome": "Welcome!"
}In pubspec.yaml:
flutter:
assets:
- assets/lang/
Import and load translations:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await T.load('mn'); // Load Mongolian translations
runApp(MyApp());
}
Access translations:
Text(T.get('hello_world'))
Switch locale at runtime:
await T.load('en');
(context as Element).reassemble();
🧠 Tip
-
Translation keys fallback to the key itself if not found.
-
You can dynamically load locales based on user settings or device locale.