Closed
Description
See comments beneath.
Description
Similar to trans_default_domain
it would be nice to also have a trans_default_locale
. Currently in Symfony 4 I did mostly do something like:
$currentLocale = $this->translator->getLocale();
$this->translator->setLocale($adminUser->getLocale());
try {
$content = $this->twig->render('my.html.twig');
} finally {
$this->translator->setLocale($currentLocale);
}
But with the introducing of the new contracts TranslatorInterface this is not longer part of that interface. And currently it seems no official way how to render a specific twig template or a part of it in a specific language.
Example
{% trans_default_locale adminUser.locale %}
{{ 'Hello %name%'|trans }}
Edit
As mention by @stof we should not focus here on the translator instead of something like a LocaleSwitcher
service which is used to update all LocaleAwareInterface services. I think the LocalSwitcher
could live Translator
component and be registered in the FrameworkBundle.
Example
$this->localSwitcher->setLocale($message->getLocale());