0
votes

I had a custom service and the translation inside it doesn't work. Symfony Version 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:
    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'.

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. Translation are found and displayed in console.

1

1 Answers

1
votes

Replace

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

With

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