Automating Localization with Github Actions: A How-To Guide

Written by localazy | Published 2020/11/15
Tech Story Tags: github-actions | github | localization | localazy | automation | language-translation | machine-translation | automated

TLDR Automating Localization with Github Actions: A How-To Guide. Localize your app the modern and developer-friendly way. Localazy translates your app to up to 80 languages for free by sharing translations with other apps. It may take some time to get used to it, but it saves you a lot of time. Localazy is the place to manage your translations, translators, and contributors. We use it extensively for building releases of our Localazy CLI tool. It's simple enough to completely remove the localization burden from your shoulders with Localazy.via the TL;DR App

Automated Localization

You have probably already heard of continuous localization. It’s important as software development is a never-ending process, and with new features, you usually need to add new strings.
Fully automated localization is a level above it. As a developer, you only set up it once, and then, you can forget about it completely.
And as we are going to useĀ Github Actions, it’s gonna be fun!

Configure Localization Platform

Let’s suppose that your mobile, desktop or web app is ready for localization, and strings in the source language are stored in JSON, YAML, iOS’ strings, Flutter’s ARB, or some other common format.
Sign up with Localazy, create a new project,Ā install the CLI tool, and then create and test yourĀ 
localazy.json
Ā configuration. You should be able to upload the source language files and download localized ones.
My configuration is as simple as:
From this moment on, Localazy is the place to manage your translations, translators, and contributors. And as a bonus, it translates your app to up to 80 languages for free by sharing translations with other apps.
Creating and testingĀ 
localazy.json
Ā is essential as it’s used by the Github actions described below.

Setup Secrets

Private data should not be committed, and so, before the commit, let’s remove the read and write keys from the configuration file above and instead place them to Github Secrets.
Create a repository on Github if you haven’t yet, go toĀ Settings > Secrets, and add keys here. My configuration looks like:

Ignore Localized Files

The source language file - in my caseĀ 
en.json
Ā - is the source of truth, and for localized files, it’s the latest version on Localazy. I don’t need those files to be committed to my repository.
With a simpleĀ 
.gitignore
Ā file placed in theĀ 
locales
Ā folder, I can filter out all localized files except for the source language one:

Automate Uploading

If you are not familiar withĀ Github Actions, I recommend reading more about it. It may take some time to get used to it, but it saves you a lot of time.Ā We use it extensively for building releases of our Localazy CLI.
The configuration below is all I need for uploading the source language fileĀ 
en.json
Ā to Localazy with each commit that changes it. I add a new feature, add new strings toĀ 
en.json
, commit it, and push it. Done.
And all you need to do now is to createĀ 
.github/workflows/upload.yml
Ā file with this content:
If you need to fine-tune it, there isĀ the documentation for the upload action on Github Marketplace.
It’s also simple to configure theĀ 
on
Ā clause to upload strings to Localazy only for releases, certain tags or branches.Ā See its configuration on Github docs.
On each push touchingĀ 
en.json
, I get this beauty:

Automate Downloading

Normally, you would integrate downloading localizable files from Localazy into your build chain, so they are added before building the release.
For clarity, let’s test just the downloading and omit other steps.
Create fileĀ 
.github/workflows/download.yml
Ā for downloading the latest version of localizable files whenever the tagĀ 
v*
Ā is pushed.
Of course, this example effectively does nothing as files are only downloaded to the action, and if we don’t use them to produce the release build, they are lost once the action is finished and cleared.
The documentation for theĀ 
localazy/download
Ā action is available onĀ Github Marketplace.
PushingĀ 
v2
Ā tag to my test repository (notice that there isĀ 
cs.json
Ā file):

Source Code

The source code of aĀ demonstrational project for this post is available on Github. Do not forget to explore the content of theĀ 
.github/workflows
Ā folder!

Closing Words

As you can see, it’s simple enough to completely remove the localization burden from your shoulders withĀ Localazy. No more file handling. All the translations of your lovely app can be managed in a single place with beautiful UI designed for developers and those that want them to bring their apps into the multilingual realm.

Written by localazy | Localize your app the modern and developer-friendly way!
Published by HackerNoon on 2020/11/15