Complete instructions for translating texts of templates and plugins in WordPress via the Loco Translate plugin. Explanation of how translations in WordPress work.
You have a website ready, the necessary plugins installed and set up, a page theme selected and activated. There is only one thing left – to provide translation of foreign expressions, which often appear in plugins and themes and which, despite the Slovak language setting, are still displayed in English.
Table of Contents
Translation function in the code of templates and plugins
The individual messages that we encounter on the website come from the program files of individual plugins and themes. If these elements are programmed correctly , WordPress uses the __ () function on all text that goes to the screen.
This function (two underscores) returns the translated text, if any. If it does not exist, it returns the basic text that is written as the first parameter. The function contains two parameters, both of which are of type String .
First: Text, required.
Second: Domain, optional.
In reality, it may look like e.g. as follows:
__('Field is required', 'contact-form-7');
This function lists Field is required if there is no translation in the current language. If a translation existed, it would list e.g. This field is required , or whatever we set it to. The second parameter ensures the uniqueness of the translation, which could be disrupted if e.g. two different plugins used the same text string.
For example, I have used two plugins on my e-shop. One that improves order options (eg some bulk edit) and the other for which we set the order of products.
Unfortunately, in English, the order and the order will say the same word – Order and so there would be a conflict in the translations:
__('order') - Objednávka
__('order') – Poradie
WordPress would “go crazy” and not know when to use the word Order and when to use the word Order . Therefore, he would use the last translated term everywhere (in this case – Order).
However, if we add the second parameter (Domain), we can safely separate individual occurrences of the same text strings :
__('order', 'order-bulk-edit') – Objednávka
__('order', 'products-order-tool') – Poradie
Therefore, I strongly recommend that you always use the second function parameter . Plug-in and theme authors often call this second parameter the name of their theme, or plugin, in an effort to ensure the highest possible uniqueness.
And of course, there are also plugins that are not programmed in this correct style, but the text strings are written in them hard-coded, in which case you will not be able to translate the texts other than directly in the code.
How to translate texts?
.Po and .mo files take care of the translation of the texts themselves. PO and MO are actually extensions of special text files that are used for translation.
PO file
.po file is a text file (it can be opened, for example, in notepad, sublime text, atom editor, or another text editor). It consists of an introductory header in which we define the basic elements of the language (language code, plural forms, …). Then they follow each other on the inverter:
msgid “original text”
msgid “translated text”
the original text is a string that goes to the __ () function as the first parameter, and the translated string is applied based on it.
MO file
The .mo file is a binary compiled .po file. So it’s a cluster of bits that aren’t human readable. But for processors, yes. For compilation we can use e.g. online converter .
We save the resulting two files in the wp-content / languages folder. It is important that they have the right name.
Basically, it is enough if we create one file sk_SK.po and one sk_SK.mo and in it we would theoretically be able to store all the texts for translation.
However, for the sake of clarity, they tend to store WordPress kernel translations separately (you will receive these with the installation of the Slovak WordPress localization), but the themes and plugins are stored in their own folders.
Instructions for translating texts via Loco
If we were to translate all the texts in the way mentioned above, it would probably be “on hold”.
That’s why plugins have been created that are more human to us than .po files , and they also handle compiling in .mo format for us.
The best known and most used is definitely the Loco Translate plugin. It’s available for free, it’s clear and it’s great to use. It can be downloaded directly from the WordPress repository ( Plugins-> Add new ).
Plugin / topic selection to translate
After installation and activation , Loco Translate will appear in the left main column of wp-admin , usually as the last item. We can directly choose whether we want to translate the topic or the plugin.
By clicking on the selected plugin, the so-called language sets, which are available to it, even with a percentage progress bar.
If the progress bar is not 100%, it is an incomplete translation. In this case, it is sufficient to translate the strings that have not yet been translated.
If our language is not available for the given plugin / theme at all, we have to add it to the language sets. We can also upload an existing .po file directly to Loco, and Loco will take care of compiling and creating the .mo file, which is needed for the translation to work properly.
Add the required language
If we do not have Slovak (or another required language) available in the plug-in, we will click on New language at the top left . A warning may pop up stating that there is no theme , in which case we will create it.
Loco runs all the files of the selected plugin and “maps” the individual translation texts.
If the theme exists, it will throw us out the possibility of adding a new language:
In point no. 1 select the language you want to add. We can either use one of the predefined languages, or we can create our own language (eg if we need a language for some unofficial language, eg dialect). In point no. 2 we then choose the location.
Custom: The translation files are saved in the folder wp-content / languages / loco / plugin / plugin_kod_jazyka.po
System: The translation files are stored in the main language global folder. Everything is OK until the WordPress kernel is updated, when these files can be deleted. Therefore, I do not recommend storing translations in this folder.
Author: A custom languages folder is created here directly below the plugin folder. Updating the plugin will delete it. I also do not recommend.
Translation of texts
After setting up, click on Start translating . The control panel will open:
In the list of texts, select the one you want to translate and click on it. It will be marked in gray, the source text will be displayed and our task is to complete the Slovak translation.
After any change, the Save button turns blue, so you can click on it to save the changes. I recommend doing it continuously. In the control panel we see the possibility to undo, this is the classic Undo , which we know from other programs (such as Word).
Other compiler options
The Sync button will help us and add or remove texts that someone (or we) will delete from the plugin files in the meantime.
By clicking on the Auto button with the robot icon we can use the automatic translation, which will provide one of the external translation engines (eg Google Translate), of course, you need to link your account via Google API. It is worth noting that today the translation is already used in large AI (Artificial Intelligence), so more than 90% of translations are done properly.
In the Filter translations field we can find the specific string we want to translate (it is almost never necessary to translate all the texts that are available). The last two buttons display blocks (if available) or display translation texts in HTML format rather than in the classic editor.
Wildcard translation
It is worth mentioning the use of wildcards. Because of this, plugin translation sometimes becomes a complete magic, because at first glance we do not know what the text is.
It is essential that the wildcard is preserved, otherwise it may malfunction, resp. incomplete translation.
The following example, I believe will be sufficient:
The wildcard usually starts with a percent sign %.
In sharp traffic on the page, instead of a wildcard, e.g. number, or specific text that is dynamic (such as a user name) and cannot be translated statically.
That is why it is very important to keep it.
Plural translation
Plurals are translated as follows:
The text for the singular and the text for the plural will appear in the source text.
Since we are in Slovakia, we use a different form of plural for 2-4 and for 5 and more (eg one car, two cars, three cars, four cars, five cars, six cars, …). It is not as simple in our country as in the case of English, where the plural differs by the letter s (1 word and 2 words), or an irregular shape (1 foot, 2 feet).
We still have to distinguish in the plural, whether it is 2-4 pieces or 5 or more pieces. We would have to define this outside the plugin at the beginning of the .po file with harakiri code, but Loco will handle it for us. We just switch to the card Several where we set the plural shape for 2-4 pieces and then the card Others , where we set the plural shape for 5 or more pieces.
We continue in this style until we have translated all the necessary strings .
WPML translation
The texts of templates and plugins can also be translated via the WPML plugin – via string translation. See this WPML translation guide for more information.
Translation via WordPress.org
If you have the time and want to help with the translation so that other WordPress users can use it as well, it is possible to translate the strings directly to wordpress.org .
First, open the selected plugin on wordpress.org, such as Elementor: https://wordpress.org/plugins/elementor/#developers .
On the Development tab, you see an underlined link Translate Elementor Website Builder into your language . You will find your language and you can design individual strings for translations. You can also help the WordPress community with this style.
WordPress Translations – Summary
In this tutorial, we have shown how the individual texts are programmed in templates and plugins to be translatable. We also showed how PO / MO files work and how it is possible to translate texts via the Loco Translate plugin .
Was this article helpful for you? Support me by sharing, please. 👍