This is a quick guide on how to translate your WordPress site using a POT file and tools involved in the process.
What framework is used for translating WP?
Using the gettext translation framework, there are three files involved in translating your wordpress site.
- POT (Portable Object Template) File
Using a program to search through your WordPress code for any text enclosed within a __e() or __() function will a POT file be generated. Within this file you will find the text available for translating. This file you will provide to your translator(s) to translate and return to you.
- PO (Portable Object) File
After you have received the translations you can then place them within the POT file and save your file as a PO file.
- MO File
The final step in the localization process is that the PO file is ran through a program that turns it into an optimized machine-readable binary file (MO file). Compiling the translations to machine code makes the localized program much faster in retrieving the translations while it is running.
Using poEdit to translate POT files
poEdit is an open source program for Windows, Mac OS X and UNIX/Linux which provides an easy-to-use GUI for editing PO and generating MO files.
Getting Started with poEdit
- Download and install poEdit
- Download the official WordPress POT file
- The poEdit screen
- Open the file in poEdit.(See Image) The box labeled(1) is the original message (in English) from the POT file. The box labeled (2) is where you add your translation. Boxes labeled (3) and (4) are used for adding comments about the messages. These come in handy if you are working with a team of translators and would like to pass around ideas through the PO file. Go to File → Save as… to save your translations in a PO file.When you are finished translating, go to File → Save as… again to generate the MO file.Or you can set your poEdit to always compile a MO file when saving changes by clicking File → Preferences and on the Editor tab check the Automatically compile .mo file on save box.
Configuring your site to use your translation files.
Now that you have your translation files prepared and ready for use you need to tell your site to use them.
Open and edit your wp-config.php file.
Set the global variable, WPLANG with the abbreviated name of the translation.
define ('WPLANG', 'language');
Where to place your translation files
Site wide translation (core wordpress code)
For text and phrases used within the core code of WordPress.
/wp-content/languages/language_COUNTRY.po
/wp-content/languates/language_COUNTRY.mo
Theme specific translation (theme specific)
For text and phrases used within themes and includes a domain within the __e() and __() functions.
Example: __e('Comment','theme_specific_domain') or __('Comment','theme_specific_domain')
/wp-content/themes/theme_directory/language_COUNTRY.po
/wp-content/themes/theme_directory/language_COUNTRY.mo
Translating Themes
Considering that themes have their own design and are custom there is a pretty good chance that there is some text that is unique to that theme and not included within the core code. For that reason, a separate or additional translation file is needed tailored to the theme (domain of the theme). Both translation functions, __e() and __() have a domain parameter which can be used to tell wordpress which translation files to use.
Configuring your theme to use its own translation files
Edit your functions.php file located within your active theme directory (/wp-content/themes/theme_directory/functions.php) and add the following before K2::init();
load_theme_textdomain('theme_domain');
K2::init();
If your domain is 'theme_domain' then your translation functions within your theme files will look similar to the following examples:
__e('Comment', 'theme_domain');
__('Comment','theme_domain');
It is good practice for theme developers to include a POT file with the theme files. In the event that you do not have a provided POT for your theme of choice you can use poEdit to scan the theme files and to generate a POT file. For instructions on how to configure poEdit to generate POT files visit http://scratch.wik.is/Translation/Translating_scratch.mit.edu/Creating_POT-Files.
After following the above steps you should now be able to reload your site with the new translations.
Sources:
- http://codex.wordpress.org/Translating_WordPress
- http://urbangiraffe.com/articles/translating-wordpress-themes-and-plugins/
- http://scratch.wik.is/Translation/Translating_scratch.mit.edu/Creating_P...
Dan's first job as a web developer was at a charter school in Camden, New Jersey. In addition to his required tasks to teach computers and act as network technician, he took the initiative to...

Comments
Post new comment