Localize your flutter application quickly and easily.

Last update: Dec 18, 2021

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,
);

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

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').

Advanced

Extension method

With the extension method, it's even easier to get a localized string ! The only thing you have to do is to replace EzLocalization.of(context)!.get('key') by context.getString('key').

You may have to manually import EzLocalization in your file.

Builder widget

EzLocalization provides a builder widget called EzLocalizationBuilder. You can use it as such :

EzLocalizationBuilder(
  delegate: EzLocalizationDelegate(
    supportedLocales: [
      Locale('en'),
      Locale('fr'),
      Locale('es'),
    ],
  ),
  builder: (context, localizationDelegate) => MaterialApp(
    title: 'Beautifully localized app',
    home: MyMainWidget(),
    localizationsDelegates: localizationDelegate.localizationDelegates,
    supportedLocales: localizationDelegate.supportedLocales,
    localeResolutionCallback: localizationDelegate.localeResolutionCallback,
  ),
);

It has two advantages :

  • It helps reducing boilerplate.
  • You can dynamically change the current locale using EzLocalizationBuilder.of(context)!.changeLocale(yourLocale).

Nested strings

You can nest translation strings as such :

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

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

Format 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'}). Also, instead of a map you can pass a list and get your arguments by their indexes.

Change the files path

You can change from the default path of assets/languages/$languageCode.json by passing getPathFunction to EzLocalizationDelegate. You will then have to provide a valid asset path according to the specified locale.

Don't forget to update your assets entry in your pubspec !

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 :

GitHub

https://github.com/Skyost/EzLocalization
You might also like...

Flutter qidgets - Build widgets hierarchies quickly with qidgets

Build widgets hierarchies quickly with qidgets. Quick widgets → qidgets. Feature

Mar 31, 2022

Quickly configure three theme styles

flytheme 快速实现三种主题效果。 本插件是从矿小助App中拆分出来的,优化了很多细节,更加简单易用。 内置持久化存储(使用share_preference实现) 矿小助App:https://kxz.atcumt.com/ pub插件地址:https://pub.dev/packages/f

Apr 21, 2022

Draggable Scrollbar - A scrollbar that can be dragged for quickly navigation through a vertical list.

Draggable Scrollbar - A scrollbar that can be dragged for quickly navigation through a vertical list.

A scrollbar that can be dragged for quickly navigation through a vertical list. Additionaly it can show label next to scrollthumb with information about current item, for example date of picture created

May 15, 2022

Aris inheritedwidget - The Inherited Widget helps you to easily distribute your app state to every widget in your Flutter app

Aris inheritedwidget - The Inherited Widget helps you to easily distribute your app state to every widget in your Flutter app

Flutter Tutorial - Inherited Widget The InheritedWidget helps you to easily dist

Dec 29, 2021

AuthorizationHeader is an open-sourced Dart library. With AuthorizationHeader, you can easily manage authorization header on your application.

A most easily usable authorization header management library in Dart! 1. About 1.1. Supported 1.1.1. Authorization Header 1.1.2. Authorization Type 1.

Dec 24, 2021

Arisonboardingscreen - Create your custom and beautiful onboarding screens easily with Flutter

Arisonboardingscreen - Create your custom and beautiful onboarding screens easily with Flutter

Flutter Tutorial - Onboarding UI Screen Create your custom and beautiful onboard

Feb 15, 2022

Easily build and deploy your Dart web app to GitHub pages

Run flutter build web or dart pub run build_runner build and put the output in another branch. An easy way to update gh-pages. Install $ dart pub glob

Apr 18, 2022

A Flutter Enterprise Software Development Architecture. Start to develop your bigger app easily.

A Flutter Enterprise Software Development Architecture. Start to develop your bigger app easily.

May 15, 2022

Easily integrate GitHub's Octicons in your own Flutter project

flutter_octicons Use the Octicon icons developed by GitHub and released under the MIT license in Flutter. flutter_octicons automatically updates itsel

May 15, 2022
Comments
  • 1. Add arguments and path, clean up

    Added {} argument, with path. Also cleaned up some parts of the code (make final when can be) and the README (also added undocumented features such as . strings).

    Reviewed by Cretezy at 2019-11-24 15:45
  • 2. Am I missing something?

    Describe the bug I'm getting Another exception was thrown: A non-null String must be provided to a Text widget. when trying to access json subtree.

    This is how the json file looks like

    {
    "bob": {
    "text1": "Hello"
    }
    }
    

    And this is how I'm getting it Text(EzLocalization.of(context).get("bob.text1"),),

    Reviewed by jonafeucht at 2020-06-15 18:39
  • 3. A way to preserve the changed locale.

    Is your feature request related to a problem? Please describe. The locale is changed using builder and it changes instantly which I am thankful for. But if I restart the app, it defaults to the original language.

    Describe the solution you'd like It'd be great if the last locale choice is preserved and it is loaded on next start. Maybe using shared preferences?

    Describe alternatives you've considered Currently, only way I can think of is by forcing a locale after getting it from stored key using shared preferences, but I'm not very comfortable forcing a locale.

    Additional context Is there a way to supply a locale as a first preference?

    Reviewed by srihariash999 at 2021-06-02 09:10
  • 4. make notFoundString required

    As of now, if you migrate the app to null safety, you'll be required to add null check on every context.getString('key').

    My suggestion is, make notFoundString a required parameter, then disable getString extension from returning null value.

    Reviewed by MkamaMakoko at 2021-03-08 16:03

Related

Show beautiful bottom sheet as confirmation dialog quickly and easily.
Show beautiful bottom sheet as confirmation dialog quickly and easily.

sweetsheet Show beautiful bottom sheet as confirmation dialog quickly and easily. nice warning success danger and since version 0.2.0 , it is fully cu

Mar 12, 2022
A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.
A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

A most easily usable cookie management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use SweetCookieJar 1

May 19, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Dec 13, 2021
A most easily usable RESAS API wrapper in Dart. With this library, you can easily integrate your application with the RESAS API.

A most easily usable RESAS API wrapper library in Dart! 1. About 1.1. What Is RESAS? 1.2. Introduction 1.2.1. Install Library 1.2.2. Import It 1.2.3.

Apr 7, 2022
Quickly is build as a tool to enhance your Flutter UI development experience and make code easier

Quickly is build as a tool to enhance your Flutter UI development experience and make code easier. It is highly inspired by Bootstrap and Tailwind CSS. It also provide lots of extension methods on String, List and Map.

Mar 14, 2022
Flutter plugin for building pull to refresh effects with PullToRefreshNotification and PullToRefreshContainer quickly.

pull_to_refresh_notification Language: English | 中文简体 widget to build pull to refresh effects. Web demo for PullToRefreshNotification Chinese blog pul

May 9, 2022
A super powerful widget to help developers build complex views quickly and comfortably.
A super powerful widget to help developers build complex views quickly and comfortably.

FSuper FSuper can help developers build complex views quickly and comfortably. It supports rich text, rounded corners, borders, pictures, small red do

Apr 14, 2022
A super powerful widget to help developers build complex views quickly and comfortably.
A super powerful widget to help developers build complex views quickly and comfortably.

FSuper FSuper can help developers build complex views quickly and comfortably. It supports rich text, rounded corners, borders, pictures, small red do

May 16, 2022
Feb 10, 2022
A Flutter widget that checks and displays the version status of application and you can easily guide user to update your app
A Flutter widget that checks and displays the version status of application and you can easily guide user to update your app

A most easily usable Flutter widget about application version check! 1. About 1.

Dec 16, 2021