Reputation: 137
I use sonata_type_date_picker to add a datepicker in my sonata admin form : http://sonata-project.org/bundles/core/master/doc/reference/form_types.html#sonata-type-date-picker-and-sonata-type-datetime-picker
I need to change the format (default : MM/DD/YYYY) to a french format, and the language also. I do this :
$formMapper->add('datedebutContrat', 'sonata_type_date_picker', array(
'label'=>'Date de prise de fonction',
'dp_language'=>'fr',
'format'=>'dd/MM/yyyy'
));
But the result is always in english.
Thanks
Upvotes: 2
Views: 6754
Reputation: 399
You should do it by extending the template SonataAdminBundle::standard_layout.html.twig and adding into the javascript bloc:
<script src="{{ asset('/bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/src/js/locales/bootstrap-datetimepicker.fr.js') }}"></script>
or use request locale as in the SonataAdminBundle::standard_layout.html.twig around line 61
In your Bundle, you extend
example my_layout.html.twig
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('/bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/src/js/locales/bootstrap-datetimepicker.' ~ app.request.locale|replace({'_':'-'}) ~ '.js') }}"></script>
{% endblock %}
And add in sonata_admin section in your config.yml:
sonata_admin:
templates:
layout: YourBundle::my_layout.html.twig
Upvotes: 2
Reputation: 69
Try to install SonataIntlBundle and configure it so that the Local will be French:
sonata_intl:
timezone:
locales:
fr: Europe/Paris
Upvotes: 0