How to Translate a WordPress Plugin
How to Translate a WordPress Plugin
If you haven’t translated a WordPress plugin before, it’s easier than you might think and doesn’t take all that long if English is your second language – or you’re a polyglot with a talent for translation.
This is the fifth post in our series on translating WordPress. Over the next week we’ve featured a new post every day on translating different aspects of WordPress. If you have any requests please me know in the comments below.
Earlier this week we looked at localizing WordPress plugins to make them translation ready. In this post I’ll show you how to translate a plugin that is ready to translate.
This post is part of our Translation Week series:
- How to Translate a WordPress Theme
- How to Localize a WordPress Theme and Make it Translation Ready
- How to Set Up the WordPress Backend in Your Language
- How to Localize a WordPress Plugin and Make it Translation Ready
- Collaborative Translations Now Available for WPMU DEV Products
- How to Translate a WordPress Plugin
- Top 6 Translation Plugins for Your WordPress Site
Finding a Plugin Ready to Translate
Before we can get started translating a plugin, we need to find one that is translation ready. This means that strings within the plugin’s code have been localized using the GNU gettext framework.
Check out How to Localize a WordPress Plugin and Make it Translation Ready for the full rundown on how to prepare a plugin for translation.
Developers don’t always create translation ready themes, so when you buy a premium theme make sure to check the plugin’s features list or ask the developer if the plugin has been localized.
Unfortunately, the WordPress plugin repository doesn’t allow you to search for plugins that have been localized, so if you download a free plugin it’s best to check the plugin’s features list to see if it is translation ready or contact the developer for more information.
WordPress uses the GNU gettext localization framework for translation. There are three types of files used in the framework:
POT (Portable Object Template) files: The first step in the translation process is using a program to search through the WordPress source code to pick out text passed into a
__e() function, generating a POT file. This file will contain all the text available for translation.
PO (Portable Object) files: The second step involves translating the text in a POT file into the target language, saving both English and translator messages in a PO file.
MO (Machine Object) files: In the last step, the PO file is converted into a machine readable format.
Translating Using Poedit
There are many translation tools available, such as GlotPress, Launchpad and Pootle, but we’re going to use Poedit. Poedit is a free, easy to use open source program for Mac OS X, Windows and UNIX/Linux for editing PO files and generating MO files.
For this tutorial we’re going to translate our plugin MarketPress eCommerce into French. If you didn’t already know, All WPMU DEV plugins come translation ready.
1.6 million WordPress Superheroes read and trust our blog. Join them and get daily posts delivered to your inbox - free!
Let’s go through this step-by-step:
1. Install Poedit.
2. Open Poedit and go to File > New catalog from POT file.
3. A catalog properties box will pop up asking for information about what you are translating. Enter the language you want to translate here along with any other details.
4. After you hit “OK” you’ll be asked what you want to name your translation file. The name is important because there’s a particular format you should follow for consistency. For example, if you’re translating Chinese for China, the file should be “mp-zh_CH.po” – mp for the MarketPress plugin, zh for the language and CH for the country. For this file we are translating to French for France so we should name it mp-fr_FR.po
Check out the GNU `gettext’ utilities to find your language and country codes.
You’ll need to save your file in the languages folder of your plugin.
5. Now we can start translating MarketPress. Poedit has a simple and straight forward interface that doesn’t involve a steep learning curve. 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 you’ve selected to translate, your translation and any notes for translators.
Translating a line of text is really easy – just select a word or phrase, enter your translation and save the file as you translate each word or phrase.
6. When you’ve finishing translating, simply save your file. Poedit will automatically create both .po and .mo files in your plugin’s languages folder.
7. Now that we’ve translated MarketPress, the next step is to upload the plugin (after we’ve zipped up again, of course) to your WordPress install either using FTP or by logging into your WordPress site and uploading the plugin by going to Plugins > Add Plugin.
Setting Up Your Translated Plugin in WordPress
As English is the default language for WordPress, you’ll need to play with a little code to force WordPress to recognize the translated files.
In order to do this, you’ll need to FTP into your WordPress install and open up the wp_config.php file and add this line of code:
define ('WPLANG', 'zh_CN');
This line tells WordPress to use French for France. When editing the wp-config.php file, you’ll need to replace fr_FR with your own language and country code.
Adding this line tells WordPress you want to use translation files for French. Since you’ve translated only your plugin and not your WordPress backend, your plugin will display in French but your WordPress admin area will continue to display in English.
Have you translated a WordPress plugin? Are there enough translation resources available? Tell us what you think in the comments below.
Image credit: cote.