888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

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.

Quick N Dirty Admin Login Screen
Login screen css?
no comment
page 128
Html 5 Gallery
Html5 image gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Display first image from post loop wordpress?
26 comments
page 1065
Post Image The Easy Peasy Way
Get image link de medium wordpress?
26 comments
page 1065
Html 5 Gallery
Html5 photo gallery?
6 comments
page 1305
Wltc Plugin Competition Live Blogging Plugin
Wordpress liveblogging plugin?
2 comments
page 1258
Html 5 Gallery
Html gallery?
6 comments
page 1305
Using Your Own Url Shortener
Create your own url shortener in php?
4 comments
page 1190
Updating Code Snippets Here
Fun plugin wordpress?
no comment
page 1338
Write One Plugin Without Repetition Deviation Or Hesitation
Saveadminoptions wordpress?
2 comments
page 27
Updating Code Snippets Here
Wordpress fun themes?
no comment
page 1338
Html 5 Gallery
Html5 photo gallery?
6 comments
page 1305
Fun With Minimalism
Sidebartabs plugin?
no comment
page 248
Using Your Own Url Shortener
Htaccess shorten url?
4 comments
page 1190
Wordpress Chat
Wordpress chat?
3 comments
page 1308
Charcoal Theme Available For Wordpress
Simple charcoal wordpress themes?
2 comments
page 959
New Tabbed Widget Plugin
Tabbedwidget on wp 29?
no comment
page 333
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Wordpress image link anchor tag?
26 comments
page 1065
Fun With Sidebar Tabs Styling
Image under sidebar css wordpress?
2 comments
page 336
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Dont Mess With My Toot Toot
Wordpress create new post type?
16 comments
page 599
Wordpress Chat
Wordpress chat themes?
3 comments
page 1308
Using Your Own Url Shortener
Url shortener?
4 comments
page 1190
Wpunlimited The Ultimate Wordpress Theme
Wordpress html customisation?
3 comments
page 1141
Quick N Dirty Bookmark Navigation
Dirty bookmarking links?
no comment
page 127
My Experience Of Flexx
Flexx theme review?
4 comments
page 1026
Categories Vs Tags Either Neither Or Both
Both either neither image?
12 comments
page 7
Premium Ithemes Review Photo Gallery
Ithemes reviews?
4 comments
page 226
3 Ways To Speed Up Your Blog Without A Cache Plugin
Comment on speed up your blog?
one comment
page 1321
Wordpress 25 Exif Fields
Wordpress exif plugin?
12 comments
page 230
Adding Settings To Admin Pages
Wordpress addsettingsfield?
3 comments
page 793
  1 query every 1158 seconds, 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…