Ojs\JournalBundle\Entity\Article::translate PHP Method

translate() public method

Translation helper method
public translate ( null $locale = null ) : mixed | null | ArticleTranslation
$locale null
return mixed | null | ArticleTranslation
    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;
        }
        /** @var ArticleTranslation $defaultTranslation */
        $defaultTranslation = $this->translations->get($this->getDefaultLocale());
        if (!($translation = $this->translations->get($locale))) {
            $translation = new ArticleTranslation();
            if (!is_null($defaultTranslation)) {
                $translation->setTitle($defaultTranslation->getTitle());
                $translation->setAbstract($defaultTranslation->getAbstract());
                $translation->setKeywords($defaultTranslation->getKeywords());
            }
            $translation->setLocale($locale);
            $this->addTranslation($translation);
        }
        $this->currentTranslation = $translation;
        return $translation;
    }