Localize and Internationalize Applications with Intl and the Flutter SDK in Dart's Flutter Framework

in #utopian-io6 years ago (edited)

flutter-logo.jpg

What Will I Learn?

  • You will learn how to localize and internationalize Flutter applications
  • You will learn how to generate and use Intl classes and code
  • You will learn how to build and use ARB files for localization
  • You will learn about Location Delegates and how to make custom Location Delegates
  • You will learn how to Localize an API with Open Weather Map's API

Requirements

System Requirements:
OS Support for Flutter:
  • Windows 7 SP1 or later (64-bit)
  • macOS (64-bit)
  • Linux (64-bit)

Required Knowledge

  • A basic knowledge of localization
  • A fair understanding of Mobile development and Imperative or Object Oriented Programming
  • Basic knowledge of how to read JSON-like data or ARB data

Resources for Flutter and this Project:

Sources:

Flutter Logo (Google): https://flutter.io/

Difficulty

  • Intermediate

Description

In this tutorial, we look at some of the ways that we can localize and internationalize a Flutter Application. We do this by making use of the Weather Application that was built in past tutorials. We are able to localize the API requests and some of the Assets in the application using the Flutter SDK and the INTL plugin.

Outline and Overview

Localization is a fairly important concept for mobile applications. It allows the developer to deploy their application to more markets and it allows users to feel more comfortable using the application. Localization can let your application target and adapt to various cultures and areas of the world in a way that is seamless. In flutter, localization is fairly non-invasive and streamlined, however, it is hidden behind a few bits of code generation.

Outline for this Tutorial
Item 1: Localizaton with l10n

The l10n localization convention is a popular way to implement localization in applications. In Dart, there are multiple different libraries that can be used to localize your applications. In Flutter, many of these libraries are baked directly into the SDK which provides a certain amount of ease of use for the developer. The Intl plugin and the flutter localization plugin are the two main plugins featured in the flutter framework. Localization in Flutter is done by way of widgets; more specifically inherited widgets.

local-delegate.jpg

Above you can see the main custom delegate implemented in our application. This delegate follows a pattern that is very similar to a typical inherited widget. We use an of method to proliferate the data that is inside of the localization class into the rest of our application just like you would with an inherited widget. The main difference is that the material application widget has properties that were designed to automatically interface with this type of widget.

Item 2: Generating ARB and Code with Intl and Intl translation

We can generate our initial ARB files after creating the skeleton for the localization class. Once we've defined the getter methods for the values that we wish to localize; we can then run a build command to generate a main template file. The syntax of these files looks like JSON and it makes use of a Key/Value pair system to allow for easy lookup and use.

arb.jpg

Here we have the main intl_messages.arb file. This is a fully generated file that allows us to create the ARB files that will be used to generate the boilerplate Dart code. You can see the two different Key/Value pairs as well as the associated meta-data . This meta-data allows other developers understand the initial intention of these ARB files and makes it easy for translators to understand the context of the attached assets.

Item 3: Flutter's Builtin Localization Delegate Classes

The Architects of the Flutter Framework chose to create more general delegate classes that can be used to add in common localization features to the application. The two main Localization Delegate classes provided in the flutter SDK are the Global Material Localizations Delegate and the Global Widgets Localizations Delegate. The Global Material Localizations Delegate automatically localizes any text or assets that are naturally a part of the widgets in the standard library. This includes pictures and text which have been incorporated into the widget library. The Global Widgets Localizations Delegate is responsible for adjusting the screen orientation of assets during localization. This includes changing text orientation from left to right to right to left depending on the language set.

delegates.jpg

Here you can see the Localizations Delegates property for the Material Application widget. In this property we have the Custom Delegate as well as the two primary default delegates. Just by placing the delegates into this list, we are able to receive the benefits from their features. Both of the general delegates have built in support for fifteen different locales and languages. Also, because the localization features are fed into the top of the application's widget tree; flutter is able to quickly and dynamically change the localization of the application.

Project GitHub Repository:

The Source Code for this project can be found here

Commands Used:

Intl Commands used in this tutorial can be found here

Video Tutorial

Projects and Series

Related Videos

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been reviewed.

Need help? Write a ticket on https://support.utopian.io.

Chat with us on Discord.

[utopian-moderator]

Hey @yokunjon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Hey @tensor! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64230.75
ETH 3149.35
USDT 1.00
SBD 3.85