问题描述
最近将应用程序从Symfony 4.3升级到4.4,在生产中我遇到了Symfony Translator界面的问题
Recently upgraded app from Symfony 4.3 to 4.4 and in production I have problem with Symfony Translator interface
config:
framework:
default_locale: pl
translator:
default_path: '%kernel.project_dir%/translations'
错误:
Fatal error: Declaration of Symfony\Component\Translation\TranslatorInterface::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale) in ./vendor/symfony/translation/TranslatorInterface.php on line 24
Fatal error: Declaration of Symfony\Component\Translation\Translator::trans($id, array $parameters = Array, $domain = NULL, $locale = NULL) must be compatible with Symfony\Contracts\Translation\TranslatorInterface::trans(string $id, array $parameters = Array, ?string $domain = NULL, ?string $locale = NULL) in ./vendor/symfony/translation/Translator.php on line 32
推荐答案
我发现降级为 symfony:translation-contracts:1.1.6
对我有用.
Composer自动安装了此包的 2.0.0
版本,该版本使用了typehinting. 1.1.6
版本不兼容,并且使 Translator
类再次兼容.
它不使用类型提示.
I found that downgrading to symfony:translation-contracts:1.1.6
worked for me.
Composer automatically installed the 2.0.0
version of this package, that makes use of typehinting.
The 1.1.6
version does not and makes the Translator
class compatible again.
It does not use typehinting.
在我的 composer.json
文件中,我将版本固定为 1.1.6
:
In my composer.json
file, I fixed the version to 1.1.6
:
"require": {
"php": ">=7.3",
"symfony/translation": "^4.4",
"symfony/translation-contracts": "1.1.6"
}
P.S.还有更多的依赖项,但出于可读性考虑,我省略了它们
P.S. There are more dependencies but I omitted them for readability
这篇关于Symfony 4.4翻译界面问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!