问题
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'
error:
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
回答1:
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.
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. There are more dependencies but I omitted them for readability
来源:https://stackoverflow.com/questions/59007287/symfony-4-4-translation-interface-problem