[英]Symfony translation in custom service not working
I had a custom service and the translation inside it doesn't work. 我有一个自定义服务,并且其中的翻译不起作用。 Symfony Version 3.2.3
Symfony版本3.2.3
Constructor: 构造函数:
public function __construct(TranslatorInterface $translator){
$this->translator = $translator;
}
Method: 方法:
public function iConvertDateTimeString(){
...
if ($dateTime === false) {
throw new \InvalidArgumentException(
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format'
),
1488549113
);
}
services.yml: services.yml:
services:
elastic_search.elasticsearch:
class: MyCompany\ElasticSearchBundle\Services\ElasticSearchService
arguments: [ "@translator" ]
exceptions.de_DE.yml: 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'.
Output: 输出:
elasticsearch.exception.service.date.wrong_format
500 Internal Server Error - InvalidArgumentException
Whats the problem? 有什么问题? Allready cleared the cache for prod and dev with warm-up after it.
Allready在进行预热后为产品和开发人员清除了缓存。 Translation are found and displayed in console.
找到翻译并将其显示在控制台中。
Replace 更换
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format'
)
With 用
$this->translator->trans(
'elasticsearch.exception.service.date.wrong_format', array(), 'exceptions'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.