Translate Translation Ready WordPress Themes
Finding a Theme Ready to TranslateFirst things first, you’ll need to find a theme to translate. But you can’t just translate any old theme – you need a theme that has been localized using the GNU gettext framework. In other words, the theme is ready to be translated. If your theme hasn’t been localized, come back later this week for a run down on how to make your WordPress themes translation ready.
Developers don’t always create translation ready themes, so when you’re buying a premium theme make sure to ask if it’s translation ready. If you just want a free theme, it’s easy to search for translation ready designs in the WordPress Themes Repository. Go to WordPress.org and go to Themes > check out our new filter and tag interface. On the next page tick “translation-ready” and click Find themes.
Once you’ve got your theme, open up the zip file and find the language folder. It should contain a POT file. 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 __() or __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 PoeditThere are a few different options for translating WordPress, as outlined in the WordPress Codex. For this tutorial, we’re going to use Poedit, an easy to use open source program available for Mac OS X, Windows and UNIX/Linux.
- Install Poedit.
- Open Poedit and go to File > New catalog from POT file and select the POT in your theme’s languages folder.
- A catalog properties box will pop up asking for information about what you are translating. Enter the language you want to translate here.
- After you hit “OK,” you’ll be asked what you want to name your translation file. The name is important and there’s a particular format you will need to follow. For example, if you’re translating Chinese for China, the file should be name zh_CH.po, and for a Tagalog translation for the Philippines would be tl_PH.po
- Now you can start translating your theme. 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.
- When you’ve finishing translating, simply save your file. Poedit will automatically create both .po and .mo files in your theme’s languages folder.
- Now that your theme has been translated, you can upload it to your WordPress install either using FTP or by logging into your WordPress site and uploading your theme by going to Appearance > Themes > Install Themes (after you’ve zipped your theme, of course).
Setting Up Your Translated Theme in WordPressAs English is the default language for WordPress, you will need to play with a little code to force WordPress to use your translated files. In order to do this, you will need to FTP into your WordPress install and open up the wp_config file and add this line of code:
<pre id="fvch-code-0">define ('WPLANG', 'zh_CN');</pre>This line specifies Chinese for China, so you’ll need to replace zh_CN with your language and country code. Adding this line tells WordPress you want to use translation files for Chinese. Since you’ve translated only your theme and not your backend, your site will display in Chinese but your WordPress admin area will continue to display in English.