Reputation: 4574
There is something I do not understand with locale management in Symfony2. I want to write month name in French with date Twig method. Is it possible? I can't do it.
It seems that my locale is not taken into account.
Here is my app/config/config.yml file:
framework:
#esi: ~
translator: { fallback: fr }
secret: %secret%
charset: UTF-8
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
validation: { enable_annotations: true }
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
session:
default_locale: fr
auto_start: true
Session locale seems good:
echo $this->get('session')->getLocale(); // Returns "fr"
die;
Yet, when I am using, in my view, the following:
<td class="month">{{ history.date|date('F Y') }}</td>
It returns me "July 2011" for instance, instead of "Juillet 2011".
What am I misunderstanding? Shouldn't the date filter be localized? If not, how can I do to retrieve correct terms? I used to use I18N to translate all the month names, but I do not think it is the best practice.
Upvotes: 3
Views: 12276
Reputation: 15002
date does not return localized string. You have to use strftime for that. Alternatively you can use SonataIntlBundle if you want more control.
Upvotes: 3