Ojs\JournalBundle\Entity\Subject::translate PHP Метод

translate() публичный Метод

Translation helper method
public translate ( null $locale = null ) : mixed | null | SubjectTranslation
$locale null
Результат mixed | null | 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;
    }