如何迫使setlocale被弃用?

问题描述 投票:0回答:1
use Symfony\Component\Translation\TranslatorInterface; .... $this->translator->setLocale($documentData->getLocale()); $html = $this->templating->render('admin/request/pdf/document.pdf.twig', [ 'data' => $data, ]); ...

一切都很好。
但然后“ Symfony \ Component \ Translation \ TranslatorInterface”被弃用,并且应该使用“ Symfony \ Contracts \ Contracts \ Translation \ Translation \ TranslatorInterface”。在新类中,不再有“ setLocale()”。
我尝试了很多事情,但我终于不知道要解决。
diD有人管理它吗?

非常感谢!

Edit:

我正在寻找一个解决方案,我可以在其中为全球树枝模板设置翻译位置。实际上,我不想为树枝中的每个钥匙写这个:

{{ 'pdf.document.title'|trans({}, 'documents', locale) }}

我想像以前一样写这篇文章:

{{ 'pdf.document.title'|trans }}

在Symfony 6.1中,已为此用例添加了LocalesWitcher。

use Symfony\Component\Translation\LocaleSwitcher; ... $this->localeSwitcher->setLocale($documentData->getLocale()); try { $html = $this->templating->render('admin/request/pdf/document.pdf.twig', [ 'data' => $data, ]); } finally { $this->localeSwitcher->reset(); }

请参见
Https://symfony.com/doc/current/translation.html#switch-locale-programathicationally-

symfony5。只要您的网站始终以您的域名开头,然后是前两个字符,之后是当前用户的de Locale,一个人可以在Twig a URL中使用请求者的语言环境创建,然后将其替换/代替。接收器。
不好,但它可以(对我来说)。
    
php symfony twig translation symfony4
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.