Translating your WordPress site using a POT file

 
Printer-friendly version
Syndicate content
Podcast

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

  1. Download and install poEdit
  2. Download the official WordPress POT file
  3. The poEdit screen
  4. 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:

 

Comments

Thanks!

Thanks for the tutorial. I liked it a lot. It may be extremely helpful.

quick help

I'm currently trying to design a wordpress site, where I integrate a blog, twitter, and customer service for my small business into the same front page. (a lot of huge conglomerates are doing similar stuff, like www.hccmis.com for example). Trying to get all of that translated together has been a chore in itself - as I'm trying to provide as well for the growing Latin American population in the states. A lot of the translator plugins that I tried either wouldn't work, or they have some other kind of issue that was holding me up. Thanks a lot for this back-end solution using POT files! I'm slowly becoming a developing expert, hah....

Help

Thx for that guidance, i've a problem...
i'm translating PO file with poEdit the problem is when i save the changes in PO file @ some point translated PO file won't apply to the theme/plugin, i mean i've to remove theme/plugin (if any) and then reinstall plugin or theme to take effect.
WP version is 2.9.2 and target plugin is Wp-ecommerce theme is simpleCart
I'll appreciate if u help me on this.

Very nice

Wow very nice found. Thanks for sharing, it will be helpful to us.

That's really great help, thx

That's really great help, thx and keep up postings , your blog is awesome.
rent villas

I'm currently trying to

I'm currently trying to design a wordpress site, where I integrate a blog, twitter, and customer service for my small business into the same front page.
photo on canvas

Many thanks for the post. I

Many thanks for the post. I find it very useful. It seems to me you've covered the idea completely. It is nice that you've given references. They helped me to understand the process better.
Best wishes, http://www.mp3hounddog.com

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options