BazingaJsTranslationBundle icon indicating copy to clipboard operation
BazingaJsTranslationBundle copied to clipboard

Don't use TranslatorFinder but use Translator::getCatalogue()

Open spiroski opened this issue 4 years ago • 2 comments

I have decorated the translator service in my project with runtime translations, but the changes from there are not reflected in the output from this bundle.

When investigating the controller, I found out that instead of using the translator's services catalogue, the bundle has it's own TranslatorFinder which finds the files, then loads them through the loader to create the catalogue:

           foreach ($locales as $locale) {
                $translations[$locale] = array();

                $files = $this->translationFinder->get($domain, $locale);

                if (1 > count($files)) {
                    continue;
                }

                $translations[$locale][$domain] = array();

                foreach ($files as $filename) {
                    $extension = pathinfo($filename, \PATHINFO_EXTENSION);

                    if (isset($this->loaders[$extension])) {
                        $resources[] = new FileResource($filename);
                        $catalogue   = $this->loaders[$extension]
                            ->load($filename, $locale, $domain);

                        $translations[$locale][$domain] = array_replace_recursive(
                            $translations[$locale][$domain],
                            $catalogue->all($domain)
                        );
                    }
                }
            }

Wouldn't it be better and more elegant to get the catalogue from the translator service? It would also work in cases like mine where I'm loading translations into the catalog at runtime, and I don't have a loader.

I can implement this and submit a PR if there is no reason to not do it that way.

spiroski avatar Jan 29 '20 14:01 spiroski

Sound a good idea, it may add (I said may) a BC break, but indeed a good idea.

kl3sk avatar Feb 06 '20 08:02 kl3sk

Any progress on this one? It would be useful change because it would allow clearing cache of translation while using https://github.com/lexik/LexikTranslationBundle

biegacz1 avatar Aug 11 '22 11:08 biegacz1