Skip to content

Commit

Permalink
Merge pull request #37 from Kunstmaan/fix-translator-loader
Browse files Browse the repository at this point in the history
fix translator loader bug
  • Loading branch information
jockri committed Apr 14, 2014
2 parents 216f2ac + 2045084 commit 3af9334
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions Service/Translator/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,22 @@
class Loader implements LoaderInterface
{
private $translationRepository;
private $translations;
private $catalogues = array();

/**
* @{@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$catalogue = new MessageCatalogue($locale);

if (!$this->translations)
{
$this->translations = array();
$translations = $this->translationRepository->findBy(array('domain' => $domain));

if ($translations)
{
foreach ($translations as $trans)
{
if (!key_exists($trans->getLocale(), $this->translations))
{
$this->translations[$trans->getLocale()] = array();
}
$this->translations[$trans->getLocale()][] = $trans;
}
if (!isset($this->catalogues[$locale])) {
$catalogue = new MessageCatalogue($locale);
$translations = $this->translationRepository->findBy(array('locale' => $locale));
foreach ($translations as $translation) {
$catalogue->set($translation->getKeyword(), $translation->getText(), $translation->getDomain());
}
}
$translations = $this->translations[$locale];

foreach ($translations as $translation) {
$catalogue->set($translation->getKeyword(), $translation->getText(), $domain);
$this->catalogues[$locale] = $catalogue;
} else {
$catalogue = $this->catalogues[$locale];
}

return $catalogue;
Expand Down

0 comments on commit 3af9334

Please sign in to comment.