app_local 1.1.0 copy "app_local: ^1.1.0" to clipboard
app_local: ^1.1.0 copied to clipboard

A Flutter package for easy app localization using JSON files, supporting device default language detection and dynamic language switching without app restart

app_local #

A lightweight, powerful Flutter package that enables instant app localization with dynamic language switching, persistent settings, and native device language support - all with minimal setup required.

Features #

  • πŸš€ Easy app localization
  • πŸ”„ Dynamic locale switching
  • πŸ’Ύ Automatic locale persistence
  • πŸ“± Phone default language support
  • πŸ”Œ Simple integration with LocaleText widget
  • ⚑ Minimal setup required

Example #

Example app demonstration

Getting Started #

1. Setup Assets #

  1. Create an assets/lang folder in your project root
  2. Add your locale JSON files (e.g., en.json, ar.json)

Assets folder structure

Example locale files:

// en.json
{
  "welcome": "Welcome to the App",
  "change_lang": "Change the language"
}

// ar.json
{
  "welcome": "Ω…Ψ±Ψ­Ψ¨Ψ§ Ψ¨Ωƒ في Ψ§Ω„ΨͺΨ·Ψ¨ΩŠΩ‚",
  "change_lang": "Ψͺغيير Ω„ΨΊΨ© Ψ§Ω„ΨͺΨ·Ψ¨ΩŠΩ‚"
}

2. Add Dependencies #

dependencies:
  flutter:
    sdk: flutter
  app_local: ^latest_version

# Add assets path
flutter:
  uses-material-design: true
  assets:
    - assets/lang/

3. Initialize #

Add this to your main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await Locales.init(
    localeNames: ['en', 'ar'],  // Your supported locales
    localPath: "assets/lang/",   // Path to your locale files
    phoneLocale: true,          // Use phone's default locale
  );
  
  runApp(MyApp());
}

Wrap your MaterialApp with LocaleBuilder:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return LocaleBuilder(
      builder: (locale) => MaterialApp(
        title: 'App Local',
        localizationsDelegates: Locales.delegates,
        supportedLocales: Locales.supportedLocales,
        locale: locale,
        home: HomeScreen(),
      ),
    );
  }
}

Usage #

Display Translated Text #

Using widget:

LocaleText('welcome');

Using string:

// Using static method
Locales.string(context, 'welcome');

// Using extension
context.localeString('welcome');

Change Locale #

// Using static method
Locales.change(context, 'ar');

// Using extension
context.changeLocale('ar');

// Switch to device locale
Locales.change(context, 'auto');

Get Current Locale #

// Using static method
Locales.currentLocale(context);

// Using extension
context.currentLocale;

iOS #

Add the following to your Info.plist file if you want to support device default language:

<key>CFBundleLocalizations</key>
<array>
  // Add your supported locales here
  <string>en</string>
  <string>ar</string>
</array>

Platform Support #

Platform Support
Android βœ…
iOS βœ…
macOS βœ…
Web βœ…
Windows βœ…
Linux βœ…

Default Native Language #

Platform Support
Android βœ…
iOS βœ…
macOS βœ…
Web 🚫
Windows 🚫
Linux 🚫

soon support web, windows, linux

2
likes
140
points
46
downloads

Publisher

verified publisherabom.me

Weekly Downloads

A Flutter package for easy app localization using JSON files, supporting device default language detection and dynamic language switching without app restart

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, flutter_localizations, intl, plugin_platform_interface, shared_preferences

More

Packages that depend on app_local