7
votes

We're creating an application in Symfony2 that is localized to Dutch and English. Now I know how to customize the Symfony error pages, but can't find how to translate the errorpages anywhere. I've tried to use the trans filter in the error templates, but it doesn't seem to use my translations file.

Also I can't find any option to make multiple error pages, one for each language, and localize them.

Does anyone know if this is possible at all, I can imagine that it's hard to implement because the error could be thrown due translation errors. But if it is I would love a hint or link on how to do this correctly.

1
Does translation of strings (using trans filter) works in any other templates? - gatisl
Well, I have to say that translation of messages in exception template does not make much sense to me, because exception could be thrown anywhere in request processing lifecycle. And also this page should not be part of normal workflow, because it represents failure in request processing and normally end user should not see it. - gatisl
@gatisl I think it does make sense, as a 404 error could be seen by a user when there is an external link that's incorrect. That's completely out of our control. Even when a 500 error would come up I want the user to be able to understand what is going on. I don't think you would be very happy with a site presenting a Chinese 404 or 500 error. - Mac_Cain13
@gatisl Translation is up and running for all other templates. So that works, it just the error/exceptionpages that I can't get translated. - Mac_Cain13

1 Answers

6
votes

You can try make use of global variables (app.request.locale or app.session.locale before symfony 2.1) which are available in templates.

{% if app.request.locale == 'nl' %}
    some error message
{% else %}
    error message in other language
{% endif %}