Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spiroski opened this issue Jan 29, 2020 · 2 comments
Open

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

spiroski opened this issue Jan 29, 2020 · 2 comments

Comments

@spiroski
Copy link

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.

@kl3sk
Copy link
Contributor

kl3sk commented Feb 6, 2020

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

@biegacz1
Copy link

biegacz1 commented Aug 11, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants