Translating Woocommerce, themes and plugins with Poedit

Recently I’ve come across the need to translate a custom theme file and it’s plugins. Initially I had issues where the translations did not work, but at the end I found out a way to translate all the strings and add new ones if needed.

Debugging translation errors

I suggest installing the plugin – Debug MO Translations. The plugin shows the information in the footer when logged in. We can see which translation files are loading on the page and if the translation files are in the correct path.

open the theme .pot file in poedit and save it as a language translation

Almost all themes have a default theme/languages/theme.pot file with all the strings that we can translate. We open the .pot file in Poedit and press the Create new translation action. We choose the language of the translation and now we’re able to start translating strings.

After the translations we save the file as theme-sl-SI and get two files theme-sl-SI.po and theme-sl-SI.mo. We copy the files to the /wp-content/languages/themes/theme-sl-SI.po and /wp-content/languages/themes/theme-sl-SI.mo. If we’re uncertain how the name of the file should start, we check with the plugin above, it’s showing us which filename and location is expected.

We use the same procedure with plugins for translating strings.

If translations are missing in the .pot file add the translation manually

One of the issues for me was that even after translating all the strings there were untranslated words on the page. The text that needed the translation was not in the source .pot file.

A simple way to solve this is to load the theme code into a code editor and do a Search of the string in all the files. When we find the string it should be in the format as bellow.

<?php esc_html_e( 'This is the string to translate', 'text-domain' ); ?>

Add translation manually to the .pot file

To add the translation manually we can open the .pot file in a code editor and at the end duplicate the last code block and add the original string from above. After that we save the translation as a language file in .po and .mo.

add translation manually to the .po file

Another way is to open the .po translation file in a code editor and duplicate the last code block.

#: woocommerce/global/quantity-input.php:44
msgid "Qty"
msgstr "This is the translation"

First line displays where the string to translate is located, second line is the original string and the last one is the translation. After we add the translation we save the .po file so that the .mo file gets regenerated automatically. With this we should have the missing translation show up on the page.