How to Create Translation for WordPress Theme

In this tutorial you’ll learn about creating translation for WordPress theme which divided into several sections:

  • Identifying which theme has ability to be translated
  • Enable Theme To Be Translated-able
  • Create .po language file and .mo file using poEdit
  • Put .mo and .po language files in the right place
  • Tool used to edit and compile your language files

Identifying WordPress Theme

To do a translation you have to make sure that the theme has ability to be translated. You have to make sure that every text/words in the theme you want it to be translated has code as below (For example, twentyten theme tag.php:15):

<?php
  printf( __( 'Tag Archives: %s', 'twentysix' ), '<span>' . single_tag_title( '', false ) . '</span>' );
?>

What you have to make sure? It is about __() function. The __() function represents that the words in the first parameter is words (‘Tag Archives: %s’) to be translated and the second parameter (‘twentyten’) is theme name.

If you found your theme is having many codes like that it possible for you to create translation.

You can learn about __() function and it equivalence to gettext function here. You’ll also need to understand about printf() and sprintf() functions.

Enable Theme To Be Translated-able

You have to make your WordPress theme able to be translated by adding code below to your theme’s functions.php:

//function
//load_theme_textdomain( 'yourthemename', TEMPLATEPATH . '/yourfolder' );

//example
load_theme_textdomain( 'twentysix', TEMPLATEPATH . '/mylanguages');
//you have to make sure that 'twentysix' or younameityourself is
//used in __() thing in Identifying WordPress Theme

It is better to create language directory alone in your theme folder in twentyten it named languages folder.

Creating .po File and Compiling .po into .mo File

Our focus here is about compiling .po file into binary .mo file. You have to download poEdit first. You can learn about basic rules of creating .po file in here.

You can also check and edit finished .po and .mo files for WordPress in here. It is better to have deep understanding by learning finished files first.

Put Your .po and .mo Files

You have to put your .po and .mo files into language directory that you create in section Enable Theme To Be Translated-able.

Choosing Language

Choose what language you want to use by adding this line to your wp-config.php:

//define('WPLANG','.mo file name without extension')
//example
define ('WPLANG', 'en_EN);

You can read about translating WordPress plugins and theme here and here. Some plugins are making translation messed up, so if you do all tutorials but it is not working, you can try to deactivate all your plugins and revert back to standard theme you have. Start the tutorial from the first.

Leave a Reply