flutter_locales
3.0.6, released 8 months ago by an unverified publisher
Easily localize Flutter apps using JSON files with dynamic locale switching and persistent storage.
What it does
Allows developers to translate a Flutter app into multiple languages using local JSON asset files. It provides widgets and extensions to change app locales dynamically at runtime and automatically saves the selected language preference.
AI-written summary of version 3.0.6, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to manage app localizations using JSON files stored in assets.
- Users need to change the app language dynamically within the UI without restarting.
- You want to remember the user's selected language across app restarts.
Skip it when
- You require compile-time type-safe keys via code generation.
- Your localization requires complex ICU message format features not handled by simple JSON assets.
Strengths
- Easy setup with JSON assets
- Runtime locale switching with automatic persistence
- Handy extensions and helper widgets like LocaleText
Weaknesses
- No compile-time verification of localization keys
- Relies on JSON asset loading rather than native ARB/Intl code generation
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Add json files in assets/locales/, declare them in pubspec.yaml, initialize Locales in main(), and wrap MaterialApp with LocaleBuilder.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Locales.init(['en', 'fa', 'ps']);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return LocaleBuilder(
builder: (locale) => MaterialApp(
localizationsDelegates: Locales.delegates,
supportedLocales: Locales.supportedLocales,
locale: locale,
home: HomeScreen(),
),
);
}
}Alternatives
Packages that do the same job and could replace flutter_locales.
- easy_localization
Popular alternative for JSON/YAML-based localization with easy setup.
64Compare - slang
Provides type-safe translations through code generation.
90Compare
Works with
Packages commonly used together with flutter_locales: ones it builds on, ones built on it, and its own family.
- intlflutter_locales depends on itA Dart library for internationalization and localization, providing message translation, plural/gender handling, and date/number formatting.
- shared_preferencesflutter_locales depends on itFlutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.