The icapps translations tool is an online tool that we wrote in order to add, edit, delete or verify translations. To make sure we can use these translations we also created plugins, libraries, scripts,... for all the technologies we work with.
You can find the package for handling translations with the translations tool here https://pub.dev/packages/icapps_translations .
We created a separate package for using localization without the translation tool: https://pub.dev/packages/locale_gen
The main goal of the icapps translations tool is to provide our clients with an easy interface to manage the translations for their app without knowing the development flow.
Developers can download the latest translations at any moment in their project. This is by default always done before a new test or production release in order to avoid delivering a new build with old translations.
In this blog post I, Koen van Looveren, will guide you through my journey of developing the icapps translations tool.
Localizations in Flutter
For every platform we have a plugin or script to easily import the translations. Since we officially provide Flutter as a service for our clients, it is important to have a good foundation on which to build our projects. One of these foundation blocks is the need for an icapps translations plugin.
When we look at the Flutter Documentation itself, it looks like it provides us with a good solution for smaller projects.
The pro’s and cons of the Flutter documentation
No automated support for the icapps translations tool (Obviously)
Translations should be added manually
All translations for every language will be in memory at any time.
No in-app language switch.
No direct support for arguments. (String, numbers). => You could write manual functions to provide this functionality. (But who wants to write manual code?)
No support for plurals or gender translations
We followed the documentation so now our code is perfect.
It looks like we are facing a lot of issues when we follow the Flutter documentation. Which is very common in mobile development. That is why we should tackle those issues with our icapps_translations plugin.
Mostly we want to autogenerate comprehensive code that will run flawlessly. I chose to use buildrunner and source_gen as plugins to help me with parsing annotations and writing new classes from the annotations. Good examples of packages that use source generation are kiwi or json_serializable.
Now, we still struggled with the problem that we can't use the annotations because everything should be generated from the icapps translations on the server.
To counter this challenge, I found that it was easier to just build a dart program that could just run from your CLI. This is a simple program that you can run from anywhere. It can access your file system and create or edit new files. Exactly what we need right? So let's get started.
1. Automated icapps translations
The first and most important aspect of this package, is the possibility to download all the translations and bundle them in our project via the asset folder.
Let's modify our pubspec.yaml to make sure the translations are always bundled with a new build.