flutter_localizations_plus 0.2.3 copy "flutter_localizations_plus: ^0.2.3" to clipboard
flutter_localizations_plus: ^0.2.3 copied to clipboard

An enhanced Flutter localization one-stop solution that streamlines multilingual integration for seamless app development.

flutter_locations_plus #

pub package pub points GitHub Issues GitHub Forks GitHub Stars GitHub License

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 (LocalizationsPlusDelegate and FallbackCupertinoLocalizationsDelegate) 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.

1
likes
0
points
49
downloads

Publisher

unverified uploader

Weekly Downloads

An enhanced Flutter localization one-stop solution that streamlines multilingual integration for seamless app development.

Repository (GitHub)
View/report issues

Topics

#localizations #locale #l10n #i18n

License

unknown (license)

Dependencies

flutter, sprintf

More

Packages that depend on flutter_localizations_plus