Easy Lang 🌍
A super simple and lightweight localization package for Flutter with zero hassle!
Make translations easy with .tr() extension, JSON files, auto language detection, and dynamic UI updates on language change.
🚀 Quick Start
Initialize localization early in your app:
await LangService().init();
Use translations anywhere with the .tr() extension:
Text('welcome'.tr());
🔁 Change Language Dynamically
Switch language easily and update the UI dynamically using setState() or ValueNotifier:
await LangService().changeLang('ar');
setState(() {});
👋 Placeholder Support (Interpolation)
Insert dynamic values inside your translation strings:
Text('hello_name'.tr(params: {'name': 'Mohamed'}));
Where your JSON has:
{
"hello_name": "Hello {name}"
}
📦 Auto UI Rebuild on Language Change
You can use StatefulWidget and call setState(() {}) after calling changeLang()
or use ValueNotifier to trigger rebuilds. No need for Provider or ChangeNotifier.
📁 JSON-Based Translations
Store your translations in JSON files like:
assets/lang/en.jsonassets/lang/ar.json
No code changes needed to add new languages — just add new JSON files.
⚙️ Features Summary
- Zero dependencies on complex localization setups: Just Flutter + Shared Preferences.
- Auto language detection: Detects device language and falls back gracefully.
- Persistent language selection: Language choice saved automatically using SharedPreferences.
- Simple
.tr()string extension: Minimal boilerplate, easy to use anywhere. - Parameter substitution in translations: Support for dynamic values inside strings.
- Easy UI rebuild on language change:
setState()orValueNotifier. - JSON file-based translations: Easy to maintain and scalable for many languages.
- Lightweight & fast: Minimal overhead and super easy integration.
🥇 Why Easy Lang vs Other Packages?
| Feature | easy_lang | flutter_localizations + intl | easy_localization | GetX Localization |
|---|---|---|---|---|
Zero boilerplate .tr() |
✅ Simple string extension | ❌ Uses code generation / ARB | ✅ Similar | ✅ Similar |
| No external CLI/tools | ✅ Just JSON & Dart | ❌ Requires ARB files + intl | ❌ Requires JSON + config | ✅ Simple |
| UI update without Provider | ✅ Uses setState/ValueNotifier | ❌ Needs manual state management | ✅ Needs setup | ✅ Built-in |
| Auto device language detection | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
| Language persistence (SharedPrefs) | ✅ Yes | ❌ Manual | ✅ Yes | ✅ Yes |
| Lightweight & minimal dependencies | ✅ No Provider required | ❌ intl package adds size | ❌ multiple dependencies | ✅ Moderate dependencies |
| Easy to understand & customize | ✅ Very simple architecture | ❌ More complex setup | ✅ Medium complexity | ✅ Medium complexity |
📦 How to integrate in your Flutter app?
- Add easy_lang as a dependency (locally or published).
- Put your translation JSON files in
assets/lang/. - Initialize
LangServiceinmain()before running the app. - Use
.tr()extension to get translated strings anywhere. - Call
LangService().changeLang('ar')+ rebuild manually usingsetState.
🧩 Example Usage
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LangService().init();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void changeLanguage(String langCode) async {
await LangService().changeLang(langCode);
setState(() {}); // Rebuild UI after language change
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('welcome'.tr())),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('login'.tr()),
Text('hello_name'.tr(params: {'name': 'Mohamed'})),
ElevatedButton(
onPressed: () {
String newLang = LangService().currentLang == 'en' ? 'ar' : 'en';
changeLanguage(newLang);
},
child: Text('change language'),
),
],
),
),
);
}
}
📝 Translation JSON Example
assets/lang/en.json
{
"welcome": "Welcome",
"login": "Login",
"hello_name": "Hello {name}"
}
assets/lang/ar.json
{
"welcome": "أهلاً وسهلاً",
"login": "تسجيل الدخول",
"hello_name": "مرحباً {name}"
}
📝 License
MIT License © Mohamed Khaled
Created with ❤️ by Mohamed Khaled
GitHub => https://github.com/MohamedKhaled8