Polyglot: Multilanguage WordPress
Let’s face it, English is the Internet language. If we would like as many people as possible to be able to read one of our posts or comments, whichever mother tonge he/she has, we must write in english. Mi interest in having a bilingual blog started almost from the very beginning. Fortunately (to me) my friend Gustavo was also interested in the same thing, so we both started to work on it (and I could learn a lot from his PHP experience
). After giving a try to many WordPress plugins to achieve internationalization we favored Polyglot over the others; it does what is needed whitout hassles.
How to use it
Installing it is way too simple, just download the file from its site and uncompress it on the wp-content/plugins folder of WordPress. Then you must activate it and (almost) ready to go, you will be able to post in as many languages as you know of. Well, actually you need to configure it (ymmv) and add a language select function on your theme’s template files. Gustavo has already posted more detailed instructions on how to do it. The interesting thing about Polyglot is that you can use it on the post, its title or the comments altoghether. To use it you just have to mark the text as you do with HTML but using lang_xx as the tag. The xx must be replaced with the ISO id of the language you are writing on. Example: suppose you would like to post both in Spanish (ISO id “es”) and in English (ISO id “en”) you should write:
< lang_es >Texto en español< /lang_es >
< lang_en >Text in English< /lang_en >
Note: Blanks should not be used within the language tags. They were added in order to make Polygot ignore them.
For titles you can use the same language tags. For the comments you need to use brackets instead of angle brackets.
Tweaks
Once Polyglot is configured and working some tweaks are needed to have a fancier site. Those tweaks might require changes on template or plugin files. This is necessary because APIs or internationalization function calls ( like __() and _e() )are not always used as it should be. Some of the changes I have made:
Language selection menu text:
I wanted to use a more descriptive text than the default raw language name on the selection menu. To achieve this the file wp-content/plugins/polyglot.php needs to be edited. Change the configuration variables near the top of the file:
$polyglot_settings['trans']['en'] = 'Also available in English.';
$polyglot_settings['trans']['es'] = 'También disponible en español.';
Language list:
With its default configuration Polyglot shows the available languages using an unordered list. I wanted to use the selection menu within the post metadata so I needed to get rid of the list. To do it I called the function with empty parms from the theme template files.
< ?php if(function_exists('lp_other_langs')) { lp_other_langs(' ','', '', '', ''); }?>
Flag and text:
The language list available for a post is made of either a flag or a descriptive text. Using both makes the selection easier.
function polyglot_other_langs(...
...
$foo = ($polyglot_settings['use_flags'] ) ? " ".get_trans($lang) : get_trans($lang);
...
Write post buttons:
Wouldn’t it be nice if we have post editor buttons to help with the many tags we will be using? We can add them to the file wp-includes/js/quicktags.js. Each entry is made of an id, label, opening tag, closing tag, associated key and a keep-open toggle (if the tag has no closing one). I have used the ISO ids as labels. The associated key is used as an Alt+key shortcut.
edButtons[edButtons.length] = new edButton('ed_es','es','< lang_es >','< /lang_es >','e');
edButtons[edButtons.length] = new edButton('ed_en','en','< lang_en >','< /lang_en >','n');
These are just a few tweaks. There are many more to do and many more comments on this issue so stay tuned…



Is there a way to make a drop down list with available languages. When selection is made the correct language loads?