ez_localization 0.2.1+1 copy "ez_localization: ^0.2.1+1" to clipboard
ez_localization: ^0.2.1+1 copied to clipboard

outdated

Setup a powerful localization system in your flutter application quickly and easily.

EzLocalization #

This package allows you to setup a powerful localization system with ease and in only a few minutes.

Features #

Here are some features:

  • Easy, lightweight, open-source.
  • MIT licensed.
  • Easily extensible.

Getting started #

It only takes a few steps in order to get EzLocalization to work !
First, add the following code to your MaterialApp definition (usually in main.dart) :

EzLocalizationDelegate ezLocalization = EzLocalizationDelegate(supportedLocales: [Locale('en'), Locale('fr')]); // The first language is your default language.

return MaterialApp(
  // ...
  localizationsDelegates: ezLocalization.localizationDelegates,
  supportedLocales: ezLocalization.supportedLocales,
  localeResolutionCallback: ezLocalization.localeResolutionCallback,
);

The definition of ezLocalization is best done outside of the build method. If you want, you can use the EzLocalizationBuilder which is an useful widget that does all of this for you.

Then you create a folder named languages in your assets directory with the defined languages in it. An example structure could be :

assets
└── languages
    ├── en.json
    └── fr.json

You can change from the default path of assets/languages/$languageCode.json by passing getPathFunction to EzLocalizationDelegate.

Here's an example of en.json :

{
  "hello": "Hello !"
}

And a translated fr.json :

{
  "hello": "Bonjour !"
}

Don't forget to add the assets in your pubspec.yml :

flutter:
  # ...
  assets:
    - "assets/languages/"

That's it! To get your string you only have to call EzLocalization.of(context).get('hello').

Nested strings #

You can nest translation strings as such :

{
  "tabs": {
    "home": "Home"
  }
}

And it can be access using EzLocalization.of(context).get('tabs.home').

Arguments #

In your translation string, you may add arguments using {} :

{
  "greeting": "Hello {target}, my name is {me} !"
}

You can then fill them with EzLocalization.of(context).get('greeting', {'target': 'John', 'me': 'Bob'}).

Instead of a map you can pass a list and get your arguments by their indexes !

Updating the iOS app bundle #

See the official flutter.dev documentation about updating the iOS app bundle.

Contributing #

You have a lot of options to contribute to this project ! You can :

23
likes
0
pub points
83%
popularity

Publisher

verified publisherskyost.eu

Setup a powerful localization system in your flutter application quickly and easily.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_localizations

More

Packages that depend on ez_localization