An enhanced Flutter localization solution that streamlines multilingual integration for seamless app development.
Android | iOS | MacOS | Web | Linux | Windows |
---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
- Flutter >=3.0.0 <4.0.0
- Dart: ^2.17.0
- sprintf: ^7.0.0
published on pub.dev, run this Flutter command
flutter pub add flutter_localizations_plus
- IMPORTANT: [locale] directory which contains json files MUST declared in pubspec.yaml.
flutter:
assets:
- locale/ # for multiple languages
- Initializes [Translations] with
supported
locales and optional parameters.
List<Map<String, dynamic>> formatted = Translations.supported([
Localization.en_US,
Localization.zh_Hans,
Localization.fr_CA,
Localization.pt_BR
], selected: Localization.zh_Hans, fallback: Localization.en_US);
- Add delegates (
LocalizationsPlusDelegate
andFallbackCupertinoLocalizationsDelegate
) to localizationsDelegates and assign supportedLocales with Translations.supportedLocales for WidgetsApp Created.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
supportedLocales: Translations.supportedLocales,
localizationsDelegates: const [
LocalizationsPlusDelegate(),
FallbackCupertinoLocalizationsDelegate()
// ... more localization delegates
],
home: const Home(),
);
}
}
- Retrieve locale JSON strings by [key]
// 1. Uses sprintf-style ordered arguments for dynamic formatting.
Translations.of(context).text("local_time_caption", DateTime.now());
Translations.of(context).text("flight_broadcast_test", ["flutter_localizations_plus", "pub.dev"]);
// 2. Fetches raw string in locale file
Translations.of(context).text("welcome_tips");
- Manually updates app's locale (e.g., from UI language settings page selections).
String locale = Localization.fr_CA;
await Translations.changeLanguage(locale);
Feel free to file an issue if you have any problem.