Tsounabe
Tsounabe

Reputation: 2184

How to get all translations message domains in Symfony

TL;DR: I would like to programmatically get all Message Translations Domains of an application made with Symfony 3.4.

An example of expected result:

$domains = $this->get('translator')->getDomains();
//$domains = ['home', 'messages', ...]

But i don't find a method returning application domains in translator service. Is there an another service returning all application domains?

Thanks!

Upvotes: 2

Views: 2313

Answers (1)

Tsounabe
Tsounabe

Reputation: 2184

Ok i found the solution:

$this->getContainer()->get('translator')->getCatalogue()->getDomains();

This solution works for bundles if you store their translations as Symfony 3.4 recommend it : in bundles/Resources/translations/ folder. Otherwise you should precise the path in in config.yml:

framework:
    translator:
        ...
        paths:
            - '%kernel.project_dir%/xxx/translations'

Upvotes: 3

Related Questions