/** * Translation helper method * @param null $locale * @return mixed|null|\Ojs\JournalBundle\Entity\SubjectTranslation */ public function translate($locale = null) { if (null === $locale) { $locale = $this->currentLocale; } if (!$locale && $this->parent !== null) { $locale = $this->parent->getCurrentLocale(); } if (!$locale) { throw new \RuntimeException('No locale has been set and currentLocale is empty'); } /** @var SubjectTranslation $currentTranslation */ $currentTranslation = $this->currentTranslation; if ($currentTranslation && $currentTranslation->getLocale() === $locale) { return $currentTranslation; } /** @var SubjectTranslation $defaultTranslation */ $defaultTranslation = $this->translations->get($this->getDefaultLocale()); if (!($translation = $this->translations->get($locale))) { $translation = new SubjectTranslation(); if (!is_null($defaultTranslation)) { $translation->setSubject($defaultTranslation->getSubject()); $translation->setDescription($defaultTranslation->getDescription()); } $translation->setLocale($locale); $this->addTranslation($translation); } $this->currentTranslation = $translation; return $translation; }