ez_localization 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new70

EzLocalization #

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

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:

└── 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:

  # ...
    - "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 !

Features #

Here are some features:

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

Contributing #

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

[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.


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:

  ez_localization: ^0.2.0

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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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.


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.15.8 0.16.0
meta 1.1.7 1.1.8
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8