自定义服务中的 Symfony 翻译不起作用
Symfony translation in custom service not working
我有一个自定义服务,但里面的翻译不起作用。
Symfony 版本 3.2.3
构造函数:
public function __construct(TranslatorInterface $translator){
$this->translator = $translator;
}
方法:
public function iConvertDateTimeString(){
...
if ($dateTime === false) {
throw new \InvalidArgumentException(
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format'
),
1488549113
);
}
services.yml:
services:
elastic_search.elasticsearch:
class: MyCompany\ElasticSearchBundle\Services\ElasticSearchService
arguments: [ "@translator" ]
exceptions.de_DE.yml:
elasticsearch:
exception:
service:
date:
wrong_format: Der DateTime String hat das falsche Format. Benutze 'Y-m-d H:i:s' oder 'Y-m-d H:i:s.u'.
输出:
elasticsearch.exception.service.date.wrong_format
500 Internal Server Error - InvalidArgumentException
有什么问题吗? Allready 清除了 prod 和 dev 的缓存,并在之后进行了预热。找到翻译并显示在控制台中。
替换
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format'
)
有
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format', array(), 'exceptions'
)
我有一个自定义服务,但里面的翻译不起作用。 Symfony 版本 3.2.3
构造函数:
public function __construct(TranslatorInterface $translator){
$this->translator = $translator;
}
方法:
public function iConvertDateTimeString(){
...
if ($dateTime === false) {
throw new \InvalidArgumentException(
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format'
),
1488549113
);
}
services.yml:
services:
elastic_search.elasticsearch:
class: MyCompany\ElasticSearchBundle\Services\ElasticSearchService
arguments: [ "@translator" ]
exceptions.de_DE.yml:
elasticsearch:
exception:
service:
date:
wrong_format: Der DateTime String hat das falsche Format. Benutze 'Y-m-d H:i:s' oder 'Y-m-d H:i:s.u'.
输出:
elasticsearch.exception.service.date.wrong_format
500 Internal Server Error - InvalidArgumentException
有什么问题吗? Allready 清除了 prod 和 dev 的缓存,并在之后进行了预热。找到翻译并显示在控制台中。
替换
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format'
)
有
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format', array(), 'exceptions'
)