Flutter Localization

Since app localization is very common with mobile app development

This article shows you step-by-step to add a flutter localization to your Flutter application. Here’s what you’re visiting build today:


The first step is to add the easy_localization as a dependency in the pubspec.yaml file

  easy_localization: ^3.0.0

Create a folder and add translation files like this

└── translations
    ├── {languageCode}.{ext}                  //only language code
    └── {languageCode}-{countryCode}.{ext}    //or full locale code


└── translations
    ├── en.json
    └── en-US.json

Declare your assets localization directory in pubspec.yaml:

    - assets/translations/

Note on iOS

For translation to work on iOS you need to add supported locales to ios/Runner/Info.plis



 Initialize library

Call EasyLocalization.ensureInitialized() in your main before runApp.

void main() async{
  // ...
  // Needs to be called so that we can await for EasyLocalization.ensureInitialized();

  await EasyLocalization.ensureInitialized();
  // ...
  // ...

Add EasyLocalization widget like in the example.

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:easy_localization/easy_localization.dart';

void main() async {
  await EasyLocalization.ensureInitialized();
      supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')],
      path: 'assets/translations', // <-- change the path of the translation files 
      fallbackLocale: Locale('en', 'US'),
      child: MyApp()

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      locale: context.locale,
      home: MyHomePage()

Change or get locale

context.locale = Locale('en', 'US');


Translate tr()

The main function for translate your language keys

You can use extension methods of [String] or [Text] widget, you can also use tr() as a static function.

Text('title').tr() //Text widget

print('title'.tr()); //String

var title = tr('title') //Static function

Now your app is ready to change the language. You can create the TranslationDemo class as a stateful widget with, widgets you want and a preferred Ui design. In your language JSON files add the words that you need to translate. Add as many as JSON files you want and add the language to supported locales. The keys that I used for my demo are as follows.


  "title" : "Title",
  "app_local_demo" : "Application localization example",
  "demo_details" : "This is a sample project to change the language with a drop down menu of languages"


  "title" : "Título",
  "app_local_demo" : "Ejemplo de localización de aplicaciones",
  "demo_details" : "Este es un proyecto de ejemplo para cambiar el idioma con un menú desplegable de idiomas"

To get the words just import the package and add the key as below example.


That’s it will meet in next article.

You’re looking for resources….

Here it is: https://github.com/umeshvision/multi_language_demo

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories