繁体   English   中英

定制服务中的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在进行预热后为产品和开发人员清除了缓存。 找到翻译并将其显示在控制台中。

更换

$this->translator->trans(
        'elasticsearch.exception.service.date.wrong_format'
)

$this->translator->trans(
        'elasticsearch.exception.service.date.wrong_format', array(), 'exceptions'
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM