Polyglot: Multilanguage Wordpress


Wordpress MultilanguageLet’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) : 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…

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
6tas. Jornadas Regionales de Software Libre
Nos vamos a Mendoza!

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

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

There is a function, polyglot_list_langs() , that gives you a list of languages available for you to choose one for the entire site. It is demonstrated on the author’s site. Look for the “Preferred language” part at http://fredfred.net/skriker/index.php/polyglot. This function can be used in a sidebar. Maybe you can have its output as an input for a drop down menu list. I have not tried to do so, my site only has two languages to choose from.

Thank you for putting me in the right direciton.

I was using lp_other_langs(’ ‘,”, ”, ”, ”)

now I’m using polyglot_list_langs() and changed the polyglot.php file a bit. I have to further tweak to get it working perfectly.

When a user changes to an other language with the dropdown box the correct language should load. I guess I have to write a javascript event listener.

thanks

hello mauricio

do you happen to know how i could display both the flag and the language name with this function (let’s you chose the language for the whole blog)


been looking for a solution now for ages.

i am offering the rss feed in different languages as well, but i would only like to display, say the english rss feeds when english is selected and the german feeds, when german is selected as the language for the blog. nobody could give me an answer so far.
i would really appreciate your help.

merry x-mas, by the way…

Hi!
I really cant manage on changing the blog visual (the sidebar with the “categories” translated to “categorias”, for example)
I did not know how or where to use the _e( ) writing mode…
Could you help me (and many more of us) with this issue or create kind of a “tutorial” explaining these procedures?

Thank you very much!

Buenas, 1 el post … una pasada de util, gracias.
2 He metido el
solo en la cabecera y me andava por la cabeza si A) puedo forzar a que se muestre siempre? B)puedo forzar a que se muestren todas mis lenguas, ahunque algun post no este escrito en ellas?
Muchas gracias otra vez.

Buenas, 1 el post … una pasada de util, gracias.
2 He metido el php if(function_exists(’lp_other_langs’)) { lp_other_langs(’ ‘, ”, ”, ”, ”); }
solo en la cabecera y me andava por la cabeza si A) puedo forzar a que se muestre siempre? B)puedo forzar a que se muestren todas mis lenguas, ahunque algun post no este escrito en ellas?
Muchas gracias otra vez.

para saver el pluguin que usas que jo tambien lo quieroooo jopeee.

Hola Mauricio, lo primero gracias por este buen post.

Estoy intentando sacar tanto el texto como las banderas dado que como comentas queda mucho mejor pero me encuentro con que al intentar usar tu código dentro de la función polyglot_other_langs() me da un error al insertar el módulo. Finalemnte he hecho mi arreglo “ad hoc” pero la verdad es que me gustaría haber entendido un poco mejor si hay una forma más elegante y correcta de hacerlo. ¿Puedes aclarar un poco donde insertarías en código justamente para hacerlo funcionar?
Yo lo he probado bajo y sobre el código en el que se introduce el valor a la variable foo y me ha fallado.
Finalemnte he tenido que hacerlo modificando la linea original del código así:

//Modificación para introducir el texto además de las banderas
$foo = ($polyglot_settings['use_flags'] ) ? “” . get_trans($lang) : get_trans($lang);

Simplemente en caso de que esten activadas las banderitas, al final le añado el texto pero queda muy feo porque claro sale la típica barra de enlace debajo de la imagen y del texto.

Gracias por tu atención y un saludo,

javi.