Ferodynamics Network

popular: profile privacy, mobile privacy

January 13, 2009

Do you know how many people use themes who do not post in English? Me neither, no idea, but I know that most themes are in English and only English. A premium theme needs to be different, it needs to think through the needs of the user and that means providing localisation. You will be amazed at how easy it us.

Before I begin here is a quick poll. I want to demonstrate, if I can, how many people there are out there who do not use English for either their blog or for the admin area of their WordPress installation:

So, how do you localise a theme? Well WordPress does all the hard work for you. As long as you decide to localise before you start then actually there is almost no work for you to do at all.

Choose a text domain

First you need to choose a text domain. This is a name that will let WordPress know which set of dictionary to use. It can be anything, as long as it is unique. I would suggest using the name of your theme. For this example I will use “Fun with WordPress”.

Tell WordPress where to find the dictionary

Next you need to tell WordPress the name of your dictionary using the load_theme_textdomain function. This should be placed at the top of your functions.php file so it loads everytime WordPress does.

[php]
load_theme_textdomain('Fun with WordPress');

You can include a second parameter in that function which is a path to the directory where the translations will be held. By default it will assume your themes directory.

Start theming

That is almost all the code you need to write. All you need to do now is to mark up your English text so that it gets translated. To do that you use two functions:

[php]
_('This is English text','Fun with WordPress');

and:

[php]
_e('This is English text','Fun with WordPress');

They both tell WordPress to perform a translation (if desired and possible) on the text in the first parameter, using the dictionary in the second parameter. The difference between the two functions is that the first does the translation and returns the result, so it can be used in code, and the second echos the result, so it can be used for normal text. Here’s an example that provides the “read more” text for posts that use the more tag.

[php]

Using this, if someone using your theme uses the more tag to show only part of the content on the home page then they can choose a translation for the text that links to the rest of the post.

Create your .po file

A .po file is the file that will contain all your English words so people can translate them. You don’t need to go through the theme and find all the words there are tools that will do that for you. I Can Localize has a free tool that will even take a zip file to do your whole theme at once.

Promote your post

This is essential. Promote the fact that your theme is localised. There are many people out there who look for themes just to provide the translations. It doesn’t matter if you can’t translate it yourself as long as you have laid the groundwork.

But wait, is it really that easy?

I’ve painted this as being really easy because it is. But of course the devil is always in the details. Premium themes are about attention to detail and so is good localisation. Take the example I showed you above. What happens if you want the text to contain the post name. You can’t simple attach it to the end as you might do with English because other languages might not use the same text order. The sprintf function is a must:

[php]
sprintf( _( 'Read more of %s' , 'Fun with WordPress' ) , the_title('', '', false) );

Now the translation can specify where the title should go as well.

One of the best resources I have come across for dealing with all these issues, including word order, dates, javascript alerts, etc, is called Localizing WordPress Themes and Plugins at I Can Localize. Last time I produced a theme I used it extensively.

If you are producing a new theme I encourage you localise it. Not least because it is the right thing to do, but also (as I hope my poll shows) there are lot of people out there with an interest.

Silence Is Golden
3 comments
page 213
Questions About Habari For Wordpress Users
6 comments
page 424
Theming Habari Vs Wordpress
13 comments
page 440
My Experience Of Flexx
4 comments
page 1026
Plugin Update Fun With Photo Data 2
one comment
page 815
Post Image The Easy Peasy Way
26 comments
page 1065
Gaining Benefits From Plugins
8 comments
page 1167
Categories Vs Tags Either Neither Or Both
12 comments
page 7
Fun With Theme Widgets
24 comments
page 867
Beware Wp Cache
8 comments
page 1310
Six Million Ways To Die Choose One
14 comments
page 1128
Post Image The Easy Peasy Way
26 comments
page 1065
Post Image The Easy Peasy Way
26 comments
page 1065
Wordpress Chat
one comment
page 1308
Post Image The Easy Peasy Way
26 comments
page 1065
Beware Wp Cache
8 comments
page 1310
Wordpress Chat
one comment
page 1308
Wp Polls Reviewed
one comment
page 58
Fun With Photo Data
12 comments
page 330
Html 5 Gallery
6 comments
page 1305
Fun With Sidebar Tabs Styling
2 comments
page 336
Using Your Own Url Shortener
4 comments
page 1190
Html 5 Gallery
6 comments
page 1305
My Experience Of Flexx
4 comments
page 1026
Fun With Sidebar Tabs
193 comments
page 57
Html 5 Gallery
6 comments
page 1305
Fun With Plugins
27 comments
page 14
Wordpress 25 Exif Fields
12 comments
page 230
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Beware Wp Cache
8 comments
page 1310
Quick N Dirty Replacement Text
no comment
page 122
Theming Habari Vs Wordpress
13 comments
page 440
Fun With Sidebar Tabs Styling
2 comments
page 336
Beware Wp Cache
8 comments
page 1310
Fun With Sidebar Tabs
193 comments
page 57
Wordpress Chat
one comment
page 1308
Wp Polls Reviewed
one comment
page 58
Quick N Dirty Admin Login Screen
no comment
page 128
  updated 1 seconds ago
Sunday, 3am
SE7EN (Nice from Thailand)

My blog is in Thai and English but I prefer my WordPress installation and theme in English

Friday, 10pm
Simon

A big Thanks, Gracias & Danke, Andrew! Will definitely use it.

Thursday, 10am
Stefano, www.wordpressmania.it

Totally agree!
For all non-english bloggers the fact that a theme is i18n ready is definitively a needed feature!
At least the premium themes need to be i18n, but very few are!

Even all the free themes listed at wordpress.org sholud be i18n ready, as WordPress is…

Thursday, 5am
Ryan

Thanks Andrew.

I've been wondering how to do this for a while for both themes and plugins.

Wednesday, 10am
Christoph

I demand every theme to be i18n ready, seriously.
While writing the sourcecode it's very easy to internationalize the theme. Putting i18n in afterwards is a huge timefactor – I did it once for Neil Mertons Web2.0* theme and it took me a whole day to test and bugfix (too bad Neil disappeared from the internet – and so did his theme).

i18n is as easy as making widget-ready sidebars. Too bad most theme authors do not care about widgets and hardcode everything inside their sidebar…