Starting with internationalization

Have a project and want to translate it into several languages? This guide will help you do so. Several typical situations are showcased, but most of the examples are generic and can be applied to other scenarios as well.

Before translating any software, you should realize that languages around the world are really different and you should not make any assumption based on your experience. For most of languages it will look weird if you try to concatenate a sentence out of translated segments. You also should properly handle plural forms because many languages have complex rules for that and the internationalization framework you end up using should support this.

Last but not least, sometimes it might be necessary to add some context to the translated string. Imagine a translator would get string Sun to translate. Without context most people would translate that as our closest star, but it might be actually used as an abbreviation for Sunday.

Choosing internationalization framework

Choose whatever is standard on your platform, try to avoid reinventing the wheel by creating your own framework to handle localizations. Weblate supports most of the widely used frameworks, see Supported file formats for more information (especially Translation types capabilities).

Our personal recommendation for some platforms is in the following table. This is based on our experience, but that can not cover all use cases, so always consider your environment when doing the choice.

Platform

Recommended format

Android

Android string resources

iOS

Apple iOS strings

Qt

Qt Linguist .ts

Python

GNU gettext

PHP

GNU gettext 1

C/C++

GNU gettext

C#

.XML resource files

Perl

GNU gettext

Ruby

Ruby YAML files

Web extensions

WebExtension JSON

Java

XLIFF 2

JavaScript

JSON i18next files 3

1

The native Gettext support in PHP is buggy and often missing on Windows builds, it is recommended to use third party library motranslator instead.

2

You can also use Java properties if plurals are not needed.

3

You can also use plain JSON files if plurals are not needed.

The more detailed workflow for some formats is described in following chapters:

Integrating with Weblate

Getting translations updates from Weblate

To fetch updated strings from Weblate you can simply fetch the underlying repository (either from filesystem or it can be made available through Git exporter). Prior to this, you might want to commit any pending changes (see Lazy commits). This can be achieved in the user interface (in the Repository maintenance) or from command line using Weblate Client.

This can be automated if you grant Weblate push access to your repository and configure Push URL in the Component configuration.

Pushing string changes to Weblate

To push newly updated strings to Weblate, just let it pull from the upstream repository. This can be achieved in the user interface (in the Repository maintenance) or from command line using Weblate Client.

This can be automated by installing a webhook on your repository to trigger Weblate whenever there is a new commit, see Updating repositories for more details.