Logen — Converting localization formats

David Piper
3 min readAug 18, 2019

--

This is part one of four articles about logen, my localization generating and converting tool. It describes why and how to use it.

Part two will provide more information about the process of converting one localization format to another one and which classes and methods are involved. The following part three will be a deep dive into the structure of the project. Last but not least the final part will show an example of how to add a new custom converter and thus extend the tool to support other formats.

So let’s get started with why you should use logen!

Why to use Logen

Whether you are creating an app for iOS or Android or any other platform, localizing the content is not a difficult task. Just add one or more files containing all localized strings and use them in your code. But it can get frustrating when you need to work on both (or more) platforms for the same app. The same content suddenly needs to be maintained in multiple different formats. If there is a typo in the localization of one platform, all other platforms need to be checked and corrected too. If there is a new string that needs to be added, all files have to be updated. There has to be a better way than doing this manually!

After some research, I did’t find an easy solution. Thus I created my own and open sourced it. You can find it here:
https://github.com/DavidPiper94/Logen

Logen stands for Localization Generator and the goal was to make a python project that generates the localization files in various formats. The tool should generate localizable files for iOS and Android from one common source. When there is only one source of truth, it’s easy to fix typos and add new content to it. Another important aspect was to make it possible to create multiple localization files so that each component of an app could bring its own localizable files. I like to structure my project into separate components which should have as little common parts as possible. Thus there shouldn`t be one big common file of localizable strings which is accessed by all components. Also the tool should be able to generate an enum for all keys, so that the keys in localizable files don’t need to be accessed as raw strings but more in an Android like way.

After we discussed why the generation of different localization formats is useful, let’s now explore how to use the tool.

How to install Logen

Installing Logen is really easy:

pip install Logen

How to use Logen

Logen provides two subcommands: convert and list.

As the name suggests, convert takes a localization file in one format and spits out another format containing the same strings. For this work it needs to know the file path of the source file as well as a path to the destination directory to which the resulting files will be written to. Since one format can contain e.g. multiple languages and another format may define one file per language, it is possible that multiple files will be created. Thus the destination needs to be a directory and not a single file. Additionally convert expects an identifier for an importing converter and an exporting converter. Each available converter needs to specify an identifier to be selectable for this subcommand. You can also add some flags. The option -d or — dryRun disables writing to files, instead the output will be written to the console. -f or — force allows you to overwrite an existing destination directory with the new files. Finally -v or — verbose gives you additional information about what’s going on.

For example, a valid command would be:

logen convert /path/to/source /path/to/destination ––force ––verbose

The second command is list. It lists all available converter, their descriptions and what identifier they have. How to define and register new custom converter will be described in part three.

That’s it for now. In the next part we will explore the project structure and look at some interesting points.

--

--

David Piper
David Piper

Written by David Piper

Working as an iOS and Android dev.

No responses yet