Start a Project

Multi-lingual in Flutter

Before starting our blog topic Multi-lingual in Flutter, let’s discuss multilingually. What is multilingual? and why do we need it in Flutter application development?

Multilingual is related to the multiple languages in that an application is supported.

Whenever we develop any application, for accessing a large number of users of different countries or different communities, your application must support the language that users understand.

With the support of multiple languages, you can ensure a large number of user groups for your application.

Let’s start the implementation of the Multi-lingual In Flutter project and get to know how we improvise the user experience of the Flutter application.

You may also check our Flutter app development services page.

1. Add the localization package into pubsec.yaml folder

We have added the flutter_localization dependency and int1 dev dependency for the null check. You can add the updated version on int1 dependency.

2. Add the Strings files in assests folder.

Now, we will add the different JSON files in the assets folder, which consists of the strings values for the application.

We have added the “en.json” & “ar.json” files, as we are doing with Arabic and English translation. You can add multiple files as per your requirements.

3. Create a Language translation file.

In this post, we will look at the process of translating a language into English. We will create a translation file, which will be used to fetch the data from the assets locale directory.

When the string name does not match with existing string then it will return the blank strings.

The LanguageDelegate class will load the LanguageTranslation class whenever a locale changes. The Delegate class check the localization is supported or not and load the language translation class when it changes. It will also extend the “LocalizationDelegate” class if the locale does not change. 

4. Use the localization in main.dart

In the material app, we will add the support for the delegate class and translation class and pass it to the parent widget:

Now, everywhere in the whole app, you should use LanguageTranslation’s “value” method to get the string values according to the locale.


Output :

Conclusion:

You can use multi-lingual to enhance the user experience and increase the number of users for your application of different languages

I hope this blog helps you to understand the basic uses of the Multi-lingual In Flutter.

Thank you for reading!!

For more information, you can visit the Dev Console.

Exit mobile version