BazingaJsTranslationBundle
BazingaJsTranslationBundle copied to clipboard
Don't use TranslatorFinder but use Translator::getCatalogue()
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.
Sound a good idea, it may add (I said may) a BC break, but indeed a good idea.
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