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 auto UI rebuild 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 UI updates automatically:

LangController().changeLang('ar');

👋 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

Wrap your app with ChangeNotifierProvider using LangController.
Whenever you call changeLang(), all widgets listening will rebuild automatically.


📁 JSON-Based Translations

Store your translations in JSON files like:

  • assets/lang/en.json
  • assets/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 + Provider + 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.
  • Automatic UI rebuild on language change: No need to manually refresh widgets.
  • 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
Auto UI rebuild with Provider ✅ Built-in with ChangeNotifier ❌ Needs manual state management ✅ Built-in ✅ Built-in
Auto device language detection ✅ Yes ✅ Yes ✅ Yes ✅ Yes
Language persistence (SharedPrefs) ✅ Yes ❌ Manual ✅ Yes ✅ Yes
Lightweight & minimal dependencies ✅ Only provider + shared_preferences ❌ 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 LangService in main() before running the app.
  • Wrap your app with ChangeNotifierProvider for LangController.
  • Use .tr() extension to get translated strings anywhere.
  • Call LangController().changeLang('ar') to switch languages dynamically.

🧩 Example Usage

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await LangController().init();
  runApp(
    ChangeNotifierProvider(
      create: (_) => LangController(),
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return Consumer<LangController>(
      builder: (_, lang, __) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(title: Text('welcome'.tr())),
            body: Column(
              children: [
                Text('login'.tr()),
                Text('hello_name'.tr(params: {'name': 'Mohamed'})),
                ElevatedButton(
                  onPressed: () {
                    lang.changeLang(lang.currentLang == 'en' ? 'ar' : 'en');
                  },
                  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