flutter_localizations_plus 0.2.2
flutter_localizations_plus: ^0.2.2 copied to clipboard
An enhanced Flutter localization one-stop solution that streamlines multilingual integration for seamless app development.
flutter_locations_plus #
An enhanced Flutter localization one-stop solution that streamlines multilingual integration for seamless app development.
Platform Support #
| Android | iOS | MacOS | Web | Linux | Windows |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Requirements #
- Flutter >=3.0.0 <4.0.0
- Dart: ^2.17.0
- sprintf: ^7.0.0
Getting started #
published on pub.flutter-io.cn, run this Flutter command
flutter pub add flutter_localizations_plus
Steps for Usage in Dart #
- IMPORTANT: [locale] directory which contains json files MUST declared in pubspec.yaml.
flutter:
assets:
- locale/ # for multiple languages
- Initializes [Translations] with locales need to support and other optional parameters.
List<Map<String, dynamic>> formatted = Translations.supported([
Localization.en_US,
Localization.zh_Hans,
Localization.fr_CA,
Localization.pt_BR
], selected: Platform.localeName, fallback: Localization.en_US);
- Add delegates (
LocalizationsPlusDelegateandFallbackCupertinoLocalizationsDelegate) 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] with support sprintf-style arguments
// 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.flutter-io.cn"]);
// 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).
// [{locale, name, abbr, region, i10n}] e.g. [{locale: "fr_CA", name: "français (Canada)", abbr: "fr", region: "CA"}]
List<Map<String, dynamic>> allSupported = Translations.allSupported;
int idxSelected = 1;
String locale = allSupported[idxSelected]["locale"]; // Localization.fr_CA;
await Translations.changeLanguage(locale);
Additional information #
Feel free to file an issue if you have any problem.