ez_localization 0.2.1

EzLocalization #

This package allows you to setup a 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.

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 :

[0.2.1] - 2020-02-04

  • Added the possibility to return a string if the given translation is not found.
  • Updated README (added a link to Updating the iOS app bundle on flutter.dev).

[0.2.0] - 2019-11-30

  • Added arguments.
  • Some fixes.

[0.1.1] - 2019-11-22

  • Some last minute fixes.

[0.1.0] - 2019-11-22

  • First public release.

example/README.md

Examples #

If you want a "real project" example, you can check this one on Github.

If you want a little snippet, go to the projet page.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ez_localization: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ez_localization/ez_localization.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Feb 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Format lib/src/localization.dart.

Run flutter format to format lib/src/localization.dart.

Format lib/src/localization_delegate.dart.

Run flutter format to format lib/src/localization_delegate.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_localizations 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
intl 0.16.0 0.16.1
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8