Cannot Translate Date

The main problem when you are translating your WordPress is to translate the date that displayed on your site.

WordPress have several functions to call the date:

  • the_date
  • get_the_date
  • date()
  • and many more

All of them can only be used to displaying when did you posts published. To translate that date, you can use a plugin for it.

The main question is how to translate the today’s date?

date

In order to displaying today’s date you can use a function for example:

<?php echo date(get_option('date_format')); ?>

My friend Josephine from France already try to translate her WordPress site using a po/mo editor, she also already use define (‘WPLANG’, ‘fr_FR’);, but there is no effect. The today’s date month/day still displayed on English language.

Since she is from France, she want to change the month label that displayed on her site. For example, January in France is Janvier.  We will need a special treatment to translate the today’s date, use this code for it:

<?php
$format = get_option('date_format');
print date_i18n($format);
?>

The main idea of those code is to use the native WordPress function named date_i18n. The date translation will give a response once you declare define (‘WPLANG’, ‘fr_FR’); on your wp-config.php file.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s