Skip to main content
Duplicate translations

Often the same strings appear at different places in your app. Learn how to use key linking and merging to avoid duplicates.

Ilya Krukowski avatar
Written by Ilya Krukowski
Updated over 8 months ago

Often the same strings may appear at different places in your website or app. In this article you'll learn how to use the Duplicate finder and perform key linking and merging to deal with duplicates.

Introduction

For example, suppose we have three "Next" buttons represented with NextButton, button_next, and next_button translation keys. They, however, will have the same translation Next meaning these keys are effectively duplicating:

In this case we will have to translate the same word thrice. But Lokalise is here to help us identify and deal with such cases easily!

Technical limitations

  • Duplicate translations over 1000 characters will be ignored by the Duplicate finder for automatic linking or merging. Please refer to manual linking for such keys.

  • Duplicate finder does not work across projects or across project branches.

Duplicate finder

Opening Duplicate finder

To get started, open the projects dashboard, find the desired language and click More > Show duplicates:

You can also open a translation project, click on the Languages dropdown, find the desired language and then press More > Show duplicates:


Duplicate finder controls

Using the top menu you can further adjust the detection options:

  • Language dropdown allows you to choose a language to search duplicates for.

  • Platforms section allows you to select one or multiple platforms where the duplicates should be searched. By default, all platforms are chosen.

If any duplicates were found, they will be displayed for you:

  • Duplicate translation is the actual duplicated translation value.

  • Keys column lists all the translation keys that contain the duplicated translation value. You can click on the key name to open it in the bilingual view.

  • For each key there are two buttons: Hide from contributors (only the project admins will be able to view the key) and Delete key.

Dealing with duplicates

Please note that while we have a bulk action to reference all languages, as well as link all keys and merge all keys, there's no bulk action to un-reference, un-link, or un-merge everything back, so be careful! You might want to create a project snapshot before proceeding.

Linking keys

To take care of duplication, you can establish a link between keys. When a link (or reference) is created, one key becomes a parent (referenced key) while all other keys become children (referring keys). Thus, when translation for the referenced key is updated, the referring keys are updated automatically as well. When the translations are downloaded back, all linked keys will be exported properly along with their translations.

To link duplicating keys, simply click Link all to selected:

The chosen key (next_button in the screenshot above) will become a referenced key while all other keys will become referring. If you want button_next to become a referenced key, simply choose it by clicking a radio box next to its name:

If you have multiple duplicating entries, you can take care of them in one go by pressing Link all with references button. Do not forget to choose a referenced key for each found entry before clicking this button:

Once the operation is completed, you will see that the referring translations are now highlighted with green:

It means that the link has been successfully established and whenever you update translations for the button_next key, all referring keys will be updated automatically.

Merging keys

Another common issue is having multiple keys with different names but similar translations that are used on different platforms. For example: CancelButton  (Android platform) and cancel_button  (iOS platform). These keys, however, will probably have the same translation, for example Cancel:

To avoid translating the same word multiple times, we can merge two keys to a single entry. To achieve that, click Show duplicates for the base language (English in our case) and press Merge to a single entry in the Duplicate Finder:

The duplicating keys will be merged to a chosen entry (CancelButton in the screenshot above). Alternatively, you may merge all found duplicates by pressing Merge all possible keys. Do not forget to choose the entry to merge to by using radio boxes next to the key names!

After this operation is completed, you will see that there is one key with different names for iOS and Android platforms:

Do not forget, however, that one key may have only one translation per language, so different platforms cannot contain different translations.

Another thing to note is that the merging operation will automatically enable the Per-platform key names option for the project. To toggle this option on or off, proceed to More > Settings and find the Miscellaneous section:

Linking and merging: a more complex scenario

Now let's discuss a more complex scenario. Suppose we have four duplicating keys assigned to different platforms:

Let's proceed to the Duplicate finder. You will note that currently it is not possible to merge all these keys to a single entry. That's because a key can contain only one name per platform, and we have two duplicating iOS keys:

Therefore, first we have to deal with the iOS entries. Uncheck all platforms in the top menu except for iOS:

Next, choose one of the keys to link to and click Link all to selected:

We've dealt with the iOS duplicates. Now you can enable all platforms once again:

As you can see, we have only one iOS key now. Choose the next_button1 key and click Merge to single entry. After the operation is completed, return to the project editor:

We've successfully dealt with all the duplicates!

Please note that in this scenario it's very important to choose a proper entry to perform the merge operation. Why?

Remember that first we've established a link where the next_button1 acts as a parent and next_button2 acts as a child. This link works by using a parent key ID. Next, when we performed the merge operation and chose next_button1 as a target, we've effectively removed two other translation keys (NextButton and next_button). However, if a different target is chosen, then next_button1 will be removed along with its ID. This, in turn, will break the previously established link and you'll have to fix it manually by replacing the non-existent ID with a new one. To avoid this problem, make sure to choose a correct merge target.

Automatically merging keys upon uploading

Whenever you upload translation files, Lokalise will detect and take care of certain duplicating keys. Specifically, if you have two translation files for different platforms, and these files contain similar keys, these keys will be merged to a single entry.

If you wish to preserve both keys without merging them, enable the Differentiate keys by file option before uploading translation files:


Did this answer your question?