In this article I show you how to translate your WordPress theme (or plugin): using Poedit or using another plugin. A fully localized and translated WordPress website requires translate contents (using WPML, Polylang, Multilingual Press, etc) and also text strings in php files (using Poedit or another plugins such as Loco Translate).
(Originally written on July 4, 2014. Updated on June 22, 2015)
If you want to make a WordPress site in one, two o more languages, there is a very important distinction to be made. A fully localized and translated WordPress website requires translate contents and text strings:
Translate contents (posts, pages, custom post types, etc)
Your content is stored in database tables. It´s not stored in files. Translating content requires a solution that reads your posts from the database and stores your translations right there.
If you want to know how to translate your content, you can read this COMPLETE GUIDE. You can use free plugins such as qTranslate or Polylang, or premium plugins such as WPML (standalone WordPress environment) or Multilingual Press Pro (WordPress Multisite).
Translating text strings (PHP files) in themes and plugins
Themes and plugins contain text strings that are in files. Whenever you see something like:
<php _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
Examples of text strings in frontend:
- “Search” (search button)
- “Nothing found” (when you search something and nothing is found)
- “Read more” (posts)
- “Leave a comment” (text to encourage the user to leave a message)
- “Comments are closed”
- “Older comments”
Examples of text strings in backend:
- “Top primary menu” (text in widgets area)
- “Ready to publish your first post?” (text in WordPress dashboard)
- “Number of posts to show:” (text in WordPress dashboard)
- “Twenty Fourteen requires at least WordPress version 3.6. You are running version %s. Please upgrade and try again” (Twenty Fourteen theme).
Tools like Poedit (which you can use for free) or plugins such as Loco Translate or Codestyling Localization let you translate text strings in your WordPress files. Also premium translations tools like WPML let you translate text strings.
1. 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.
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.
- Responsive WordPress theme: wp-content/themes/responsive/languages/responsive.pot
- Contact Form 7 plugin: wp-content/plugins/contact-form-7/languages/contact-form-7.pot
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):
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.
2. 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.
This program has a Pro version that enhances Poedit with additional features and benefits such as dedicated WordPress support, Word Count, etc. It costs $19.99.
Here are the steps:
1. Open Poedit and select File > New Catalog from POT / PO file
2. Select the .POT file or the .PO file from the theme or plugin you wish to translate which (you can find the files in the wp-content/themes/your-theme/language/ folder).
3. A box will pop up asking for language of the translation. Select your language:
4. Hit OK and Poedit will name automatically your file. If you select Spanish (Spain): es_ES.po
5. Save your file in your computer
6. Now you can start translating your theme or your plugin. The space at the top will display all the text ready to translate, and any completed translations will display to the right. The boxes underneath show the source text, your translation and any notes for translators. Translating is really easy – just select a word or phrase, enter your translation and click “Validate”.
- You have to respect all special characters from the original text when translating (look at the screen capture)
- It´s not necessary translate all text strings. Perhaps you don´t want to spend your time translating text strings of the admin theme.
7. 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.
2.2. Loco Translate
Loco Translate is the best plugin to translate WordPress themes and plugins directly in your WordPress dashboard.
The Loco Translate plugin is great for localizing WordPress themes and plugins.
- PO editor within WordPress admin
- You can create and update language files directly in your plugin or theme
- Extraction of translatable strings
- MO file compilation
- PO file backups
- Built-in WordPress locale codes
2.3. Codestyling Localization Plugin
(EDIT: this plugin has disappeared)
Another popular option is Codestyling Localization plugin. You can manage and edit all translation files (.PO/.MO) directly out of your WordPress dashboard without any need of an external editor (such as Poedit).
Codestyling Localization plugin detects the gettext ready components like WordPress itself or any plugin or theme supporting gettext. This plugin is able to scan the related source files and can assists you using Microsoft Translator API or Google Translate API during translation.
After you have installed and activated the plugin, simply go to Tools > Localization and translate the theme or plugin from your WordPress admin following the plugin instructions.
Anyway, if you’re an experienced computer user, I recommend you to use Poedit to translate your themes or plugins, which is more complex but you don’t need to install another plugin.
This is the second article in the series on WordPress 100% Localized and Translated