In this guide, you will learn how to translate a WordPress plugin or theme into your language using Poedit which is a free program to write translations.
The plugin or theme needs to be translation ready before we can translate it to a different language.
Now, to check if the plugin or theme is translation ready, we need to check if the author of the plugin or theme has provided the .pot (portable object template) file or the .po (portable object) file.
The .po file contains the actual translation and the .pot file is a template for creating the .po file (actual translation). So, the author may provide the actual translation into some language (.po file), or just the .pot file.
Means, we can either use the .pot or the .po file to write the translation of plugin or theme into our language.
Now, in the WordPress installation directory of your server, navigate to the “wp-content” directory. Here, you will see “plugins” and “themes” directory. In the plugins directory, you will find all the installed plugins and installed themes in the themes directory.
Let’s assume we are going to translate a theme named “Galaxis”, so we will open the “themes” directory. And, inside this directory, we will open the directory with the theme. In this case, the name of the directory is “galaxis”.
Here, you will find all the theme files and folders. So, we just need to look up for language files (.pot or .po files). Generally, these files are inside of the language or lang directory of the theme. In this case, it’s the “galaxis.pot” file.
Once, you have found the language file, download it to your local PC. Now, we need to follow these steps:
- Download and install Poedit as per your operating system.
- Open Poedit and click on “Create new translation”.
- Browse the .pot or .po file that you downloaded earlier. In this case, the file name is “galaxis.pot”.
- Now, you will be asked for a translation language. So, select the language in which you want to translate. Here, we select the French language.
- After selecting the language, you can start translating the text. To do so, click on the text and write its translation in the “Translation” field below.
- Here, you will also be able to see translation suggestions for the text.
When you are done with translations, click on the “Validate” and then the “Save” button. This will generate the .po and .mo (Machine Object) files. The .mo file is the binary file that the machine can read and it is generated from the .po file.
So, we have fr_FR.po and fr_FR.mo files ready. Now, we just need to move them to the “wp-content/languages/themes” directory inside the WordPress installation directory of your server.
If you can’t find the “languages” directory inside of wp-content. Then, you can create it. Similarly, depending upon what you are translating, you will need to create another directory (themes or plugins) inside of the “languages” directory.
There is one more step before moving the language files. We need to rename them so the theme or plugin text-domain appears first, then the dash (-) followed by the file name. In this case, we will need to rename “fr_FR.po” and “fr_FR.mo” to “galaxis-fr_FR.po” and “galaxis-fr_FR.mo” respectively.
You can find the text-domain of theme or plugin inside of the style.css file of the theme and the main file of the plugin (generally, its plugin-name.php).
Finally, move the language files to the “wp-content/languages/themes” in case of theme translation or “wp-content/languages/themes” in the case of plugin translation.
Lastly, you can check to see if the translation is working by changing the language of your WordPress site.
Go to your WordPress admin area, “Settings” > “General” > “Site Language” to change the language.
You can repeat the same process if you see new strings (text) added to the translation file in the theme or plugin updates.