private function normalizePublisherTypes() { $this->io->newLine(); $this->io->text('normalizing publisher types'); $this->getContainer()->getParameter('locale'); $this->io->progressStart(); $publisherTypes = $this->em->getRepository('OjsJournalBundle:PublisherTypes')->findAll(); foreach ($publisherTypes as $publisherType) { $getTranslation = $this->em->getRepository('OjsJournalBundle:PublisherTypesTranslation')->findOneBy(['translatable' => $publisherType, 'locale' => $this->locale]); if (!$getTranslation) { $this->io->progressAdvance(); $newPublisherTypeTranslation = new PublisherTypesTranslation(); $newPublisherTypeTranslation->setTranslatable($publisherType); $newPublisherTypeTranslation->setLocale($this->locale); $newPublisherTypeTranslation->setName('-'); $this->em->persist($newPublisherTypeTranslation); } } $this->em->flush(); $this->io->newLine(); }
/** * Translation helper method * @param null $locale * @return mixed|null|\Ojs\JournalBundle\Entity\PublisherTypesTranslation */ public function translate($locale = null) { if (null === $locale) { $locale = $this->currentLocale; } if (!$locale) { throw new \RuntimeException('No locale has been set and currentLocale is empty'); } if ($this->currentTranslation && $this->currentTranslation->getLocale() === $locale) { return $this->currentTranslation; } $defaultTranslation = $this->translations->get($this->getDefaultLocale()); if (!($translation = $this->translations->get($locale))) { $translation = new PublisherTypesTranslation(); if (!is_null($defaultTranslation)) { $translation->setName($defaultTranslation->getName()); $translation->setDescription($defaultTranslation->getDescription()); } $translation->setLocale($locale); $this->addTranslation($translation); } $this->currentTranslation = $translation; return $translation; }