Symfony 4.4 Translation interface problem

跟風遠走 提交于 2019-12-08 03:15:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!