I am working on a PHP code in which I want to display month name in French.

 if (false !== strpos($translated_tz['diff'], '-')) {
            $ts = date_sub($altered_timestamp, date_interval_create_from_date_string($translated_tz['diff']));
 } else {
            $ts = date_add($altered_timestamp, date_interval_create_from_date_string($translated_tz['diff']));
 <?php if (ICL_LANGUAGE_CODE == 'fr') {    

 <?php echo esc_attr(date_format($ts, 'j F ')) . '<span>' . esc_attr(date_format($ts, 'H:i')) . '</span>'; ?>  // Line A

 <?php } ?>

Code at Line A displays the following (in which month name is in English):

 20 November 03:56

Problem Statement:

I am wondering what changes I should make in the PHP code above so that it displays month name in French.

  • try the function date_i18n
    – Kaperto
    Nov 20, 2019 at 21:03
  • @Kaperto I am wondering if you can give me brief pointer how we can achieve that through date_i18n. Nov 20, 2019 at 21:11
  • 1
    esc_attr() is a function for escaping strings. It's not a translation function.
    – butlerblog
    Nov 20, 2019 at 21:18

1 Answer 1


Here is my solution, which has been tested and works:

// Timestamp to format (defaults to current time)
$timestamp = time();

// Set language code
$dateformat = new IntlDateFormatter(
    'fr_FR', // Use valid Locale format
    IntlDateFormatter::LONG, IntlDateFormatter::NONE

// Set date format

// Echo (and capitalize) formatted timestamp
echo ucfirst( $dateformat->format( $timestamp ) );

It seems that many valid locales can be found here: https://gist.github.com/jacobbubu/1836273

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.