ez_localization 0.2.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

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 :

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

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+1] - 2020-03-06 #

  • Updated README.
  • Updated dependencies.
  • Added an EzLocalizationBuilder widget.

[0.2.1] - 2020-02-04 #

  • Added the ability 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.


import 'package:ez_localization/ez_localization.dart';
import 'package:flutter/material.dart';

/// First plugin test method.
void main() => runApp(_EzLocalizationDemoApp());

/// The demo material app.
class _EzLocalizationDemoApp extends StatelessWidget {
  Widget build(BuildContext context) => EzLocalizationBuilder(
        delegateBuilder: createEzLocalizationDelegate,
        builder: (context, localizationDelegate) => MaterialApp(
          title: 'EzLocalization Demo',
          home: Scaffold(
            appBar: AppBar(
              title: Text('EzLocalization Demo'),
            body: _EzLocalizationDemoWidget(),
          localizationsDelegates: localizationDelegate.localizationDelegates,
          supportedLocales: localizationDelegate.supportedLocales,
          localeResolutionCallback: localizationDelegate.localeResolutionCallback,

  /// Allows to create the localization delegate.
  EzLocalizationDelegate createEzLocalizationDelegate() => EzLocalizationDelegate(
        supportedLocales: [

/// The main demo widget.
class _EzLocalizationDemoWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    print(EzLocalization.of(context).get('format', {'name': 'Bond'}));
    print('If your language is set to French or Spanish, here\'s the word "Hello !" in your language :');
    print('(Otherwise it should display a simple "Hello !".)');
    print('Oh, and here\'s an apple : ' + EzLocalization.of(context).get('fruits.apple') + '.');

    return Padding(
      padding: EdgeInsets.all(8),
      child: Center(
        child: RichText(
          text: TextSpan(
            children: [
                text: EzLocalization.of(context).get('format', {'name': 'Bond'}) + '\n\n',
                style: Theme.of(context).textTheme.body1.copyWith(fontSize: 28, fontWeight: FontWeight.bold),
              TextSpan(text: 'If your language is set to French or Spanish, here\'s the word "Hello !" in your language :\n'),
                text: EzLocalization.of(context).get('hello'),
                style: Theme.of(context).textTheme.body1.copyWith(fontSize: 18, fontWeight: FontWeight.bold),
              TextSpan(text: '\n(Otherwise it should display a simple "Hello !".)\n\n'),
              TextSpan(text: 'Oh, and here\'s an apple : ' + EzLocalization.of(context).get('fruits.apple') + '.'),
            style: Theme.of(context).textTheme.body1.copyWith(fontSize: 18),
          textAlign: TextAlign.center,

Use this package as a library

1. Depend on it

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

  ez_localization: ^0.2.1+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';
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 Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

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.

Format lib/src/widget.dart.

Run flutter format to format lib/src/widget.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.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