
How to make a translatable WordPress theme
Althought English is the most represented language over the Internet, it is a good thing to think about people who speak other languages and offer them trabslated WordPress theme. In this step-by-step tutorial, you’ll learn how to take a WordPress theme and make it translatable for any language.
1 – Add the needed functions
Let’s start by the basics: Paste the following lines of codes on your functions.php file.
load_theme_textdomain( 'Cats Who Code', TEMPLATEPATH.'/languages' ); $locale = get_locale(); $locale_file = TEMPLATEPATH."/languages/$locale.php"; if ( is_readable($locale_file) ) require_once($locale_file);
On line 1, you see the load_theme_textdomain() function. This function allow you to load a Text Domain. You can pick up any name, but keep in mind that it have to be unique. So the best practice should be to use your theme name.
2 – Internationalize your theme
For translating our WordPress theme, we’re going to use the php gettext functions.
GetText has two functions: _e and __ (two underscores).
The “_e” function is used to print “simple” text, and the __ function is used when the text to be displayed is already wrapped in php tags.
Examples:
<?php _e("The page you're looking for doesn't exist", "Cats Who Code"); ?>
<?php the_content(__('Read more...', "Cats Who Code")); ?>Notice again the text domain name (Cats Who Code) above, remember that it should be the same as in the functions.php file.
The boring part is that you have to replace each single string by the required function. Depending on how many strings your theme have, this can take a lot of time. I’ve heard of some GNU tools to easily extract strings from files, but as I never tried it I can’t say anything about it. For those interested, google xgettext.
3 – Create your .po file
Now, your WordPress theme can easily be translated to any languages. But to display text in a foreign language, you have to add a .po file.
.po files stands for Portable Object. basically, theses files contains a string, and its translation in another language. For example, if you download the French version of WordPress, you’ll have a fr_FR.po file in the archive. This file contains all the translations needed for your theme to speak French, so your theme will say Bienvenue instead of Welcome.
Good news, you don’t have to search throught your theme files for all the string to be translated. A free online tool named icanlocalize.com can scan PHP files and create .po files for you ICanLocalize will extract all strings wrapped in __(“txt”, “domain”) and _e(“txt”, “domain”) calls. Strings can be enclosed in either double quotes (“) or single quotes(‘) and with any character encoding.

Po files can be edited with PoEdit, a free software especially dedicated to that task:

As you probably guessed, you have to translate each text string. Once you translated it all, save the .po file. PoEdit will also generate a .mo file, which is basically a compiled version of the .po file.
4 – Implementation
Right now, you have done the most “difficult” part of the job. The only thing you have to do is to define your WordPress locale.
To do so, the first thing to do is to get your language and country code. For example, if your language is French and France is your country of residence, your code will be fr_FR. The GNU gettext manual contains pages to help you find both your country and language codes.
Once you have your codes, open your wp-config.php file and look for the WPLANG constant. If it exists, simply replace the existing code by yours. If it doesn’t exists, simply paste the following line (with your own code, of course)
define ('WPLANG', 'fr_FR');Sources
The following articles has been very useful to me for writing this post. Thanks to the authors.
- Making it Translatable – Internationalize / Localize WP Themes
- Premium themes are translatable themes




43 Comments + Trackbacks
8.17.2009
I strongly recommend *not* to use something as “Cats Who Code” as the textdomain, but preferably something like “catswhocode”. A textdomain with spaces (and mixed case) is a loud call for file problem depending on the platform.
8.17.2009
@Ozh: Good advice, thank you!
8.17.2009
Use the plugin Localization and you have no problems and many support at the translation: different files for frontend and backend, automaticly transaltion via Google API and more, the best tool for translate a plugin or theme.
@ozh: right, it must use a string without empty and -
8.18.2009
You’ve cited a nice idea about translation. Hopefully, this works out for either a plugin or theme once I use it.
8.18.2009
Interesting – but I am actually looking at something that would CHANGE the language, based on the client browser’s preferences…. is there something like that available (I guess I would have to build upon the solution here and add stuff to detect the client’s language)…
Obviously, the challenge would be to create at least the static pages 1x per language and then select them dynamically…
8.18.2009
Great guide
8.18.2009
Nice tut. Thanks for it!
8.18.2009
Great instructions. Tutorials that provide screenshots and step-by-step instructions are completely invaluable.
8.18.2009
useful post, thanks !
8.19.2009
Very informative topic!
I wonder how many people actually struggle with translating a theme. I guess I take it for granted since I speak English.
8.20.2009
Thank you for your guide.
8.20.2009
I like this tutorial
Thanks
8.24.2009
Cheers, this will come in handy for a project I’m working on!
8.24.2009
I usually solve this problem by defining a contant with a unique name and use this constant in the load_theme_textdomain() function and all gettext functions.
8.25.2009
Good tips, thank you!
8.31.2009
Great guide! Screenshots are very useful so that we can follow the tutorials in a step-by-step manner. I’d better try this one.
9.4.2009
Thank you, very helpful.
9.7.2009
Cool code. Thanks for the information.
9.7.2009
Another way to make translatable WordPress themes is to create a WordPress child theme using a parent theme framework such as Thematic that has the translation capability already built in.
http://www.spicywebdesign.com/so-you-want-to-create-wordpress-themes-huh-the-remix/
9.10.2009
informative tutorial. thanks a lot. Have to implement it for its functionality.
9.22.2009
What affect does this have for search engines? Is each translation have it’s own unique URL? Or does it maintain it’s URL structure and just translate the page? We offer search engine ranking services, but I haven’t encountered anything regarding multi-language websites, so I’m very curious if this has any added value from a marketing perspective..
9.26.2009
That’s good explanation, thanks for the lesson very much.
Nia
10.9.2009
Hey!
Whats the best way to make a multi language wordpress blog? I tried some plugins but none of them really impress me. Does anyone have any experiences with this and any good advice?
11.2.2009
for some reason I get:
“Fatal error: Call to undefined function load_theme_textdomain() in /home/content/01/5138501/html/blog/wp-includes/functions.php on line 27″
anyways regarding a good tool for wordpress translation I use WPML widget and it is phenomenal!!