user1213510 user1213510 - 27 days ago 6
Twig Question

Symfony translations use always default EN

I have italian language set on my browser, but symfony localization give me only english translations.
How can I get italian strings if i access the page with italian browser?

Now i see "pluto" in EN Browser and in IT Browser.

Config.yml:

parameters:
locale: en

framework:
translator: { fallbacks: ['%locale%'] }


messages.en.yml:

Pippo: pluto


messages.it.yml:

Pippo: paperino


index.html.twig:

{% block body %}
<div class="container">
<div class="row">
<div class="col-sm-12">
{% trans %}
Pippo
{% endtrans %}
</div>
</div>
</div>
{% endblock %}


Thanks

Answer

If you want to set current locale from headers you need to a make an event listener for kernel.request event that sets $request->setLocale(...).

See similar questions: