Multilingual WordPress
Running a WordPress weblog in several languages simultaneously, means translating and coordinating several components in WordPress. Here are some ideas and solutions to this…
The things to be taken into account are:
Wordpress’ code
The error messages, control panel and texts which are part of Wordpress code may be easily translated thanks to the fact that Wordpress uses a PHPized version of gettext, the GNU/Linux standard on multilingual code. The translation process consists of:
- Mark every string in the code and templates as translatable, by wrapping them with functions
__()and_e(). - Process every file with the tool
xgettext, which produces a.pot(Portable Object Template) text file on which translators can work. - Every translation is saved to a new file of the same format, but different extension:
.po(Portable Object) - These are then compiled by the tool
msgfmtinto a.mo(Machine Object) file, which is ready to be saved by the users underwp-includes/languages.
There’s a lot written on this: at the wordpress wiki there’s a complete descripction of the process, at the WordPress support page there are some comments and gettext’s documentation has everything you need, just to name a few docs. As usual, Google is of great help.
So, having all the code translated is as easy as getting the right translations file in .mo format and copying it in wp-includes/languages/ with the right name. Once this is done, just edit wp-config.php modifying the line which reads
define ('WPLANG', '');
to define WPLANG to hold our favourite language:
define ('WPLANG', 'es_ES');
It’s important that the .mo files and WPLANG follow the same naming convention; i.e.: for the spanish spoken in Spain: es_ES (followed by the file extension, of course), although if you are going to use Polyglot, as I suggest later, this convention changes.
Templates’ code and text.
I use a template very similar to WP’s default, which is in its turn based upon the Kubrick theme, but in its 1.5.2 version, it’s not ready to be used out of the box with gettext so you have to download a different one.
There were a couple of problems with this “international” version, though they’ll certainly be quickly solved. For instance, there’s a typo at lines 62, 63 of the file wp-contents/themes/default/comments.php:
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
$redirect_url = get_option('siteurl').'/wp-login.php?redirect_to='.get_permalink();
should obviously read:
<?php if ( get_option('comment_registration') && !$user_ID ) :
$redirect_url = get_option('siteurl').'/wp-login.php?redirect_to='.get_permalink(); ?>
Once the files copied, new translations of the .mo have to be copied into wp-includes/languages/.
This new files should hold all the new strings and translations, but, unfortunately some are missing in the versions I found. If you want to download mine, you can here, it’s the one being used right now, so it might have things you don’t need. The .po file is also available for download.
Posts and pages
Posts should be translatable too. In order to have this, I use some tags from Polyglot, a very useful WP plugin.
Though the early Polyglot versions required a bit of effort (like hooking to many filters, etc.), the one I use, 0.6, not only translates posts, titles and categories, but it also selects the language via WPLANG from a selection made by the user or the browser’s configuration, so the language for the whole WP is changed.
But, if you are going to make use of the gettext translations, it is important that they be named not as they should (for instance, es_ES.mo), but using Polyglots scheme, which is two letters after the ISO639 standard.
To input the text in several languages using Polyglot, a special tag is introduced.
<lang_es>Here goes the english text</lang_es>
<lang_en>Y aquí el texto en español</lang_en>
Titles and category names can also be translated, though for the latter you’ll probably have to ALTER the category_name column in the database to hold more than the default 55 characters.
The comments
This is the only unsolved part for the moment. It should be easy to use the currently selected language configuration to automatically add the right tags to any comments posted, but the comments should be preprocessed before displaying and counting not to take into account those for another language. Of course it might be desirable to see them all, so there should be messages like “There are no comments in spanish, but there are 3 in french”, with “french” being a link to change the language.
As you can see, I haven’t implemented this yet. Maybe one day…


November 1st, 20065:03 am at
Do you know how can i translate Archive title ?
I always got french Archive title like “octobre 2006″ since my blog is localized in french.
I use polyglot and it works pretty good but i can’t seen to find how i can make it switch between Archive title in french and english.
Let me know.
Thanks!
November 1st, 20065:08 am at
I have seen your Archive title are translating between spanish and english.
Could you tell me how you achieve it?
It would be really helpful for me!
Thanks gain!
November 1st, 20068:08 pm at
Hi,
I have checked your site (guybouchard.ca), and if I understand your question well, you want two things:
WordPress (at least the version I use, 1.5.2) uses an internal array
$monthdefined inwp-includes/locale.phpto store the names of the months which are used everywhere in the site (and in our case in functionget_archives(), inwp-includes/template-functions-general.php). This array holds gettext-translatable strings of the form__('January'), etc.In order to have these translated, you have to add them to your
fr_CA.po(or whatever it is called) file. Do that by adding stuff like the following to the file:msgid "January"
msgstr "Janvier"
msgid "February"
msgstr "Février"
Actually the untranslated strings should already be there since they are supposed to be tagged as translatable by means of the
__()in the code, and thus should have been extracted byxgettext. If they are not tagged, you’ll want to add the necessary calls to__().Once you are done with the translation, you’ll need to call
msgfmtupon that file, then upload the result to your thewp-includes/languages/directory asfr.mo.Alternatively you may want to look for a translations file with the strings already there
.
Since I have added many little changes (and kept no log nor used any version control, shame on me) I’m not sure this is all you’ll need, but try to add the following lines to your
wp-content/plugins/polyglot.phpfile:add_filter('category_description', 'lang_picker',1);
add_filter('category_long_description', 'lang_picker',1);
Now the usual
<lang_xx>tags for category titles will work for the sidebar as well. You’ll probably also want to increase the size of thecategory_descriptioncolumn in the database.I hope this helped you…
Cheers!
November 1st, 200611:58 pm at
The translation of month is already working BUT i always have the french name like octobre . The viewer choose english language and i still get french month name in my get_archive().
Your website seem to switch month name between language fine.
I supposed i have to modify something else but i don’t know what!
Thanks for helping.
November 2nd, 200612:26 am at
Hmm… I’m kind of clueless, but:
In
polyglot.php: is your$polyglot_settings['lang_change_locale'] = TRUE;? This tells polyglot to change the global WP language setting…And this one is a bit unrelated, but given any big enough piece of software one never knows:
In
wp-config.php: is yourWPLANGvariable set to anything? It should be with a line likedefine('WPLANG', 'en');, though that shouldn’t change much, since polyglot defaults to some language and your problem seems to be with WP localisation…