Skip to content

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

License

Notifications You must be signed in to change notification settings

leo1394/flutter_localizations_plus

Repository files navigation

flutter_locations_plus

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

An enhanced Flutter localization 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.dev, 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 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 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]
    // 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);

Additional information

Feel free to file an issue if you have any problem.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published