In this article I show you how to translate your WordPress theme (or plugin) using Poedit. A fully localized and translated WordPress website requires translate contents and also text strings in php files.
Translating text strings (PHP files) in themes and plugins
Themes and plugins contain text strings that are in files. Whenever you see something like:
_e( 'Text', 'a-text-domain' )
in a PHP file of a theme or plugin, then you need to translate them.
Text strings can appear in the backend and in the frontend
- Text strings: .POT, .PO and .MO files
WordPress themes are localized using the GNU gettext framework. That’s the common way for WordPress itself and every theme or plugin. However, developers don’t always make translation ready themes, so when you use or buy a theme (or plugin) make sure to check it.
Many WordPress themes are multilingual ready. They must contain the correct files: .POT, .PO and .MO files.
1.1. Portable Object Template (POT)
The master theme (or plugin) translation file is a .POT file. Basically, the .POT file is a list of all the text lines used in the theme files in English language
Developers use tools (like gettext) that scan the PHP source and produce a .POT file, which contains a list of all the original texts, which need translation.
The .POT file is put at your disposal by the plugin or theme developer and it’s used as a starting point to create new translations. WordPress doesn’t use it.
The .POT file can be found in the theme languages folder and in the plugin languages folder.
Sometimes language folder is called lang (not language) and sometimes .POT files come with .PO and .MO files, and with a README.TXT file (instructions for translators)
1.2. Portable Object (PO) and Machine Object (MO)
The .PO file includes the original texts and the translations in two columns. It´s a translation that someone else started (the author, a professional translator, a WordPress theme user, etc), and maybe completed. WordPress doesn’t use it.
Perhaps your theme or plugin is already translated. Example: if you see a file called es_ES.po, your theme is already translated into Spanish (es) of Spain (ES). You can check out here to find your language and country codes.
The .MO file includes the exact same contents as PO file. The two files differ in their format. While a PO file is easy for humans to read, MO files are compiled and are easy for computers to read. WordPress gets translations from .MO files.
The .MO file is automatically created by Poedit whenever you save a PO file. All you can do with these files is to upload or re-upload them whenever you create or update a .PO file.
- How to translate a WordPress theme (or plugin)
Poedit is a software (available for Windows, Mac and Linux) which you can use to translate the theme or plugin. It’s available for free on poedit.net. Free version comes with a builtin translation memory that remembers your past translations and uses them to make suggestions for similar texts.
for example, translating the language into spanish for the “Camis WooCommerce Order Upload” plugin.
Here are the steps:
When you’ve finished, save your file. Poedit will automatically create both .po and .mo files. You´ll have to upload both to your theme’s languages folder.