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)
INDEX
1. Text strings: .POT, .PO and .MO files
1.1. Portable Object Template (POT)
1.2. Portable Object (PO) and Machine Object (MO)
2. How to translate a WordPress theme (or plugin)
2.1. Poedit
2.2. Loco Translate Plugin
2.3. Codestyling Localization Plugin
Introduction
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.
In this article I show you how to translate text strings: using Poedit, Loco Translate or Codestyling Localization Plugin. But first of all is important to know what are .POT, .PO and .MO files.
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.
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.
Examples:
- 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):
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.
2. How to translate a WordPress theme (or plugin)
2.1. Poedit
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”.
IMPORTANT:
- 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.
Features:
- 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
Farhad says
Hi Irena,
That is really nice explanation, May I know how to split the Theme’s .po file to backend strings and front-end? In this case we can save time to just translate front-end for website visitors.
Irena Domingo says
Hi Farhad,
You can’t split .po files in WordPress. The only option is using a theme that has been developed with two .po files (one for the backend and other for the frontend)
Usana says
Thank you Irena… I found your post very usefull.
Irena Domingo says
Thank you
Caue Rego says
Codestyling link is now broken. I think it’s discontinued, but of course I could be wrong.
Do you happen to know if there’s any standard into translating a plugin AND contributing to them?
Something like https://www.transifex.com , maybe. That one have no adoption in wordpress, as I see it, so maybe there’s some other similar stuff.
Irena Domingo says
Thanks. It seems that the plugin is no longer maintained.
Have a look at this article about contributing to translate themes and plugins:Translation Management and Collaboration Platforms for WordPress Developers
Nino says
Hi,
Ok, when translation is made and mo&po files are generated, how to include them to be used by wordpress?
FOr instance, I have spanish site and want to include english, where to define which site to show to visitor?
thx
Irena Domingo says
Hi Nino, about your two questions:
1. You have to upload .mo and .po files to your server in the language folder of your theme or plugin
2. Settings > General > Site language
Miriaam says
Hi. Irena. Great post. How to sett up the po. File to have 2 or more languages. I need to use the theme in 2 versions according to the language selected. How this can happen?
Irena Domingo says
Do you need your website in two languages? Then you have to use a multilingual plugin. Have a look at this article: Best translation plugins.
Mohamed Fayeck says
Hi, i need ur help please
i am working on translating a theme ,
actually am not planning to translate all theme 100%
so what well happen if i leave some words without translation and saved the .mo file ?
Irena Domingo says
In this case, contents without translations will be in English
BigBankClub says
Great Article!! High fives!
Irena Domingo says
Thanks!!!
soheil says
Hi
that’s perfect.
I have a question .i translate bookly extension and upload it to my language folder but it didn’t work . i try with loco extension too,i have translated file in po and mo but when use the extension it’s english.
i open the extension
translate it
save it
and uploud it
ok ,i think bookly should work!!!!
is there any misunderstanding?
Mindaugas says
Hi, I am trying to translate with Loco Translate, looks good, but how to translate different words for numbers like
1,21,31,41,51,61,71,81,91 comment(s) – komentaras
2-9,22-29,32-39,42-49,52-59,(so on) comments – komentarai
10-20,30,40,50,60,70,80,90,100 comments – komentarų
Lithuanian language.
Thank You for suggestion.
Irena Domingo says
Copy and paste numbers in the field of translation
sabry suleiman says
Great Article!! Thanks Irena
Kenan says
How can I find in a theme source code, the used .po or .mo files? For example; is the language file name de_DE.po or themename.po?
mikael christiansen says
Thanks for a good article, it is something that I can use
lucy4g says
Hey Irena,
This is very useful post you share
as a WordPress user
I am Thankful to You.
Raza IVIOI-ISIN says
Very helpful and clear and simple article .. thank you dear
as says
Not clear what is to do… i not have a PO and a POT file on my plugin. Never can start a new po file….
I need a how to to make a starting po file from my plugin, with Poedit on windows
Jessica Peltier says
Hi lrena,
Amazing ! your post very helpful,I love this.
trampoline review, Jumpsport Trampoline, https://www.youtube.com/watch?v=PyJKoQzoW0w
Mohammad Khataan says
Is Loco plugin have option to make suggestions for similar texts like “Poedit”