How to use run time downloaded localization arb/json file in flutter?
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.
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
],
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, 2022Comments
-
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 about 3 yearswow 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 about 3 yearsThat 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 replaceHttpReqService.getJson
with your typicalhttp.get
but keep in mind the return value and exceptions. -
glavigno about 3 yearsthe 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 yearsI made a improved version for this project, you can get it in this repo.