Translate Your Flutter App in Seconds

Alberto Azinar
ITNEXT
Published in
4 min readMar 1, 2024

--

Introduction

As developers, we all know the hard work, we put in to translate our Flutter app so we can “ship” it to multiple languages. Just thinking about going through all the strings and translating them one by one can even make us lazy long before we get the job done.

To mention that it´s not just laborious to translate an app manually, sometimes it can also evolve financial costs hiring multiple human translators to get the app translated to multiple languages. In this case, having a machine translating your app can be much easier and at no cost, and thanks to LeanCode we have this sorted out for us.

The Advantage of using arb_translate package

Below I mention the positive aspects arb_translate brings to us:

Less Task Execution Time and Effort

Using this package can reduce the time of translating your app to seconds and this can help you delivering a feature in less time. For instance, if a manual translation may take you 2 hours, it can be translated in just seconds using this tool.

Less Human Error Prone

Translating your app manually can lead us to poorly written words. But using this tool, if the words on your template file (eg: app_en.arb) are written correctly, so everything else will be well written.

How to use arb_translate on your flutter app

Get Gemini API Token

We need to go to Google Ai for developers portal and click on Get an API key button.

  1. Consent to the Generative AI APIs Additional terms of service and Continue.

2. Create the API key clicking on the Button Create API key

click on API Key

3. Create API key on new Project, or an existing one if already have one (created before).

Dependency installations

Install arb_translate dependency from pub.dev getting the latest version.

Add it to the pubspec.yaml file under dependencies and then run flutter pub get.

Replace <latest version> with the actual package latest version

Or install it from command line running the command below:

flutter pub add arb_translate

Now add this configuration on the l10n.yaml file located at your project root.

arb-dir: lib/l10n
arb-translate-api-key: {API-KEY}
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
use-escaping: true

You can place your API-KEY directly on the arb-translate-api-key variable like in the configuration above. You can also store the API-KEY on an environment variable by executing the command:

export ARB_TRANSLATE_API_KEY={your-api-key}

Now, make sure you have the template file with data you want to translate.

{
"solgan": "Everything is a widget",
"dash": "Learning to Fly",
"true_story": "Mozambique has one the most beautiful beaches in the world",
"profileTitle": "Profile",
"profileMyAccountLbl": "My Account",
"profileSettingsLbl": "Settings"
}

Next, lets create the file name of the respective language you want to translate to, in my case is app_pt.arb file.

By the time I execute the command:

arb_translate

The app_pt.arb file will be filled with Json data containing the Portuguese version of the content in the app_en.arb file.

If the command arb_translate is not recognized try to execute the command dart pub global activate arb_translate

Conclusion

Nowadays, having an app that can be used in different languages it´s a must (even if it´s just for in country sue). During the development cycle, you might be working to deliver this feature and it´s important to save time during the process, LeanCode has provided us a powerful tool to avoid wasting time on translating our language Json files, from hours to seconds.

Happy Coding.

Thank YOU! For reading this article. I hope it helped you with understanding this topic in a different perspective.

If you have any doubts or you may thing something is missing, you can contact me on twitter or telegram. I would be happy to talk to you about it.

Everything is a Widget!

--

--