How to Set Up Multilingual Map Labels in QGIS

Working in a team with foreign colleagues on QGIS projects, I had a task of displaying map labels in several languages: Russian, English, and Tigrinya. Which one to use depends on who is working on the project. Below I introduce a possible approach to solving this problem. The idea came up to my mind when I saw the Natural Earth dataset.

For this example, I prepared a map of the provinces of Eritrea. You can download an archive containing one shapefile and a QGIS project file (version 3.10.0-A Coruña). In the layer attributes, there are three fields: name_en, name_ru, and name_ti. The two characters after the underscore correspond to the language name code (ISO 639-1 standard).

Through the top menu, open ProjectProject PropertiesVariables. Click on the plus button and create a new variable with the name lang_code and the value en, which is now available in all Expression Editors of the QGIS project.

Next, go to Layer PropertiesLabels. There we create a regular single label and open the Expression Dialog (button in the form of the Greek letter epsilon). We need the label field name to be created dynamically based on the project variable lang_code. For this, we write:

eval(concat('"name_', @lang_code, '"'))

The eval function evaluates the entire expression inside the brackets, which is a string. The concat function combines multiple lines into one. In the case when we set the project variable lang_code to en, we get the value "name_en". Pay attention to double quotes around the edges – they are needed so that QGIS interprets the resulting string precisely as a field name, and not just a character set.

We did it! A similar operation must be repeated for all layers of the map, after which it is enough to change the project variable lang_code once to display map labels in the desired language.

There is another approach that will allow you to localize many elements of QGIS project and not just map labels (forms, names of layers and groups, field names etc.). The bottom line is to use a translation file generator and a particular program for localization (for example, Qt Linguist). Read more about TS files in the QGIS speaks a lot of languages post.

Comments (1)

Teklay Tesfazghi

This is great work. As maps are now playing key role in peoples day to day life, preparing them for different langues is an important task.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.