S.S. Intrepid

Jul 04 2008

Get help with WordPress and French locale dates and times

Have you ever had to develop a WordPress-powered website in a language other than English?

WordPress has the capability to serve your pages in the language of your choice. The WordPress community has already translated it into many languages, and there are themes, translation files, and support also available in many other languages.

With a client project I’m just about to roll out, I had to present all the content in Canadian French but keep the administrative interface in English. The translation tasks mostly fell into the realms of content, interface and layout graphics, making it a fairly smooth process. However, I did come across one small hiccup regarding post meta data dates and times, and wanted to document and share the solutions here.

In particular, I needed to translate this meta data:

This entry was posted on Tuesday, June 17th, 2008 at 5:37 pm and is filed under [category].

into French:

Cette entrée a été inscrite le mardi, 17 juin 2008 à 17 h 37 et elle est classée sous [category].

It’s simple enough to translate text in single.php, but what about the date and time which are generated using the WordPress function, the_time()?

First, the file wp-includes/locale.php needs to be translated to include the French names of the days of the week and months. Using the FR .po file available from the WordPress Subversion repository, I edited the locale file. This can be downloaded here, and is intended to be used with WordPress version 2.0.0.11.

Next, you’ll need to edit the two instances of the time function in single.php:

<?php the_time('l, j F, Y') ?>

<?php the_time('G \h i') ?>

Along with the translated text, you should now have this in your single.php template:

Cette entr&eacute;e a &eacute;t&eacute; inscrite le <?php the_time('l, j F, Y') ?> &agrave; <?php the_time('G \h i') ?> et elle est class&eacute;e sous <?php the_category(', ') ?>.

And there you have it!

Comments
blog comments powered by Disqus
Page 1 of 1