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





My name is Jean-Baptiste Jung and I'm the man behind Cats Who Code. I started to use the Internet back in 1998 and started to create websites three years laters in 2001.
24 Comments
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.
@Ozh: Good advice, thank you!
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 -
You’ve cited a nice idea about translation. Hopefully, this works out for either a plugin or theme once I use it.
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…
Great guide
Nice tut. Thanks for it!
Great instructions. Tutorials that provide screenshots and step-by-step instructions are completely invaluable.
useful post, thanks !
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.
Thank you for your guide.
I like this tutorial
Thanks
Cheers, this will come in handy for a project I’m working on!
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.
Good tips, thank you!
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.
Thank you, very helpful.
Cool code. Thanks for the information.
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/
informative tutorial. thanks a lot. Have to implement it for its functionality.
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..
That’s good explanation, thanks for the lesson very much.
Nia
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?
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!!
19 Trackbacks
[...] How to make a translatable WordPress theme Share and Enjoy: [...]
[...] more here:Â How to make a translatable WordPress theme Share and [...]
[...] How to make a translatable WordPress theme SHARETHIS.addEntry({ title: "How to make a translatable WordPress theme", url: [...]
[...] How to make a translatable WordPress themecatswhocode.com [...]
[...] Archive » Network를 Valuation하는 방법Create your own private Twitter site using WordPressHow to make a translatable WordPress theme Published RichWP.comì˜ ë¬´ë£Œ ì›Œë“œí”„ë ˆìŠ¤ 테마, Magazine Light Recent posts:Daily Digest for [...]
[...] • How to make a translatable WordPress theme [...]
[...] http://www.catswhocode.com/blog/how-to-make-a-translatable-wordpress-theme [...]
[...] from the CatsWhoCode.com blog there’s a few helpful hints on making your WordPress theme easily translatable: Althought English is the most represented [...]
[...] from the CatsWhoCode.com blog there’s a few helpful hints on making your WordPress theme easily translatable: Althought English is the most represented [...]
[...] o seu template Wordpress em multi-lÃngua, de uma forma eficiente e funcional. Os colegas do CatsWhoCode realizaram uma selecção de informação interesante acerca do assunto, e o resultado é o [...]
[...] step-by-step tutorial, you’ll learn how to take a WordPress theme and make it translatable for any language. Read This [...]
[...] Como hacer un Theme WordPress Traducible en Cats Who Code [...]
[...] ArtÃculo original en inglés [...]
[...] Ñтатьи «How to make a translatable WordPress theme«, автор Jean-Baptiste [...]
[...] Not everybody blogs in English, and neither should your WordPress theme be exclusively coded that way. With the help of localization plugins you can ensure that the next WordPress theme you’re building has text that can be translated into different languages. Cats Who Code has a great tutorial on it. [...]
[...] o seu template Wordpress em multi-lÃngua, de uma forma eficiente e funcional. Os colegas do CatsWhoCode realizaram uma selecção de informação interesante acerca do assunto, e o resultado é o [...]
[...] articolo sull’argomento è stato pubblicato su Cats Who Code, anche se necessita di qualche approfondimento, specie dal lato della creazione del modello per le [...]
[...] of your Wordpress Theme, to make sure it can be translated and adapted to other languages. See: How to make a translatable Wordpress theme, more info at the Codex on Translating Wordpress, and this summary of I18n (also at the Codex). [...]
[...] Not everybody blogs in English, and neither should your WordPress theme be exclusively coded that way. With the help of localization plugins you can ensure that the next WordPress theme you’re building has text that can be translated into different languages. Cats Who Code has a great tutorial on it. [...]