Multilingual WordPress Sites

// June 7th, 2009 // Web

Over the last month I’ve been building a tri-lingual site for an excellent little farm in Tuscany, Corzano e Paterno, where among other things they make prize winning cheeses, olive oil and wines (all of which I recommend trying whilst staying in one of their villas – really, it’s great!)

The one requirement that caused me the biggest headache was the need to handle three languages.  There are quite a few plugins which can handle two, but only a handful which manage three or more and almost all aren’t actually that easy to use and/or reliable.  In the end, after much experimentation, I settled on the excellent qTranslate which really beat all of the others hands down. Highly recommended.

qTranslate integrates nicely into the WordPress page and post admin UI, offering multiple header fields and extra tabs for each language you want to add:

qTranslate WordPress plugin's Admin UI

For standard functions, everything is great and works seamlessly.  However if you need to directly access the contents of a field in a post/page object, things will look a bit weird:

<?php echo($single->post_title); ?>

will look on the page like:

EnglishItalianoDeutsch

generating the following actual markup:

<!--:en-->English<!--:--><!--:it-->Italiano<!--:--><!--:de-->Deutsch<!--:-->

So what to do? Well, fortunately, we can just hijack a function hat qTranslate uses itself to resolve the current translation for any field – replace the :

<?php echo(qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($single->post_title)); ?>

It’s that simple – wrap that function around any multilingual property you need to read, and qTranslate will do all the heavy lifting for you!

Share and Enjoy

  • Digg
  • TwitThis
  • LinkedIn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Slashdot
  • email
  • Print
  • PDF

Leave a Reply