views:

42

answers:

2

In a template I display the day and month of a specific date :

<div class="jour"><?php echo date('d',strtotime($content->getCreatedAt())) ?></div>
<div class="mois"><?php echo date('M',strtotime($content->getCreatedAt())) ?></div>

This works fine, problem is the month name is in English. Where do I specify that I want the month names in another locale, French for instance ?

A: 

default_culture only applies for the symfony internationalisation framework, not for native PHP functions. If you want to change this setting project wide, I would do so in config/ProjectConfiguration.class.php, using setlocale, and then use strftime rather than date:

// config/ProjectConfigration.class.php
setlocale(LC_TIME, 'fr_FR');

// *Success.php
<div class="jour"><?php echo strftime('%d',strtotime($content->getCreatedAt())) ?></div>
<div class="mois"><?php echo strftime('%b',strtotime($content->getCreatedAt())) ?></div>

Note that this requires locale settings to be enabled on your machine. To check, do var_dump(setlocale(LC_ALL, 'fr_FR')); If the result is false, you cannot use setlocale to do this and probably need to write the translation code yourself. Furthermore, you will need to have the correct locale installed on your system. To check what locales are installed, do locale -a at the command line.

lonesomeday
+3  A: 

Symfony has a format_date helper among the Date helpers that is i18n-aware. The formats are unfortunately badly documented, see this link for a hint on them.

Maerlyn
Yeah... That would be a much nicer way to do it! I'll leave my answer up as a general PHP solution, however.
lonesomeday
Can format_date display the name of the month ? I can't seem to find documentation on it.
Manu
Nevermind, found it - http://trac.symfony-project.org/wiki/formatDateHowTo
Manu