How to use run time downloaded localization arb/json file in flutter?

1,660

Solution 1

I made a simple multilanguage Android app with GetX and Hive.

This project does the following tasks, it:

  • toggles between different languages,
  • installs new languages packages from external sources, and
  • offers local data persistence.

multilanguage app

After installing new language packages the app needs to restart for the changes to take effect.

The source code can be found here.

UPDATE August 7, 2021

A new version of this project was released here.

Solution 2

I used the flutter_i18n package on a Flutter project. It allows to retrieve translations from a remote source, thanks to the NetworkFileTranslationLoader class.

To use it, you need to add it to your localizationsDelegates as shown in the documentation. The example below shows how to load all translations files from the static directory on a remote server.

localizationsDelegates: [
        FlutterI18nDelegate(translationLoader: 
          NetworkFileTranslationLoader(baseUri: Uri.https("example.com", "static")),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
],
Share:
1,660
Harin Kaklotar
Author by

Harin Kaklotar

A versatile, high-energy mobile application developer with the distinction of executing prestigious projects of large magnitude within strict time schedule. 6+ years of experience in android with java and kotlin, also work with flutter.

Updated on December 20, 2022

Comments

  • Harin Kaklotar
    Harin Kaklotar over 1 year

    I have read so many tutorials and blogs on flutter localization. They use arb/json file for localization from the assets folder or l10n folder. That is the fixed language list. Means if I use English localization and now at run time I want to provide Spanish/Chinese/Italian/French to the user then I have to put that localization arb/json file in the project and then user can use that language. So is there any way that I can download the localization file at run time and use it in the app? Is there any library available to do that?

  • Harin Kaklotar
    Harin Kaklotar about 3 years
    wow this is the perfect example. Thank you. in the example "wnetworking" package is missing. cold you please update the repo or provide a link where I can get wnetworking package. +1
  • Harin Kaklotar
    Harin Kaklotar about 3 years
    That is interesting. but how do I use it? any article/tutorial/demo...
  • Ουιλιαμ Αρκευα
    Ουιλιαμ Αρκευα about 3 years
    wnetworking package is not ready to publish yet, it contains operations related to API, etc. You can replace HttpReqService.getJson with your typical http.get but keep in mind the return value and exceptions.
  • glavigno
    glavigno about 3 years
    the package documentation i attached to my answer gives you all the steps to make it work. i just highlighted the localizationsDelegates because this is where translations files are retrieved from a remote source.
  • Ουιλιαμ Αρκευα
    Ουιλιαμ Αρκευα over 2 years
    I made a improved version for this project, you can get it in this repo.