Get the node translation for a node

@param HasNodeInterface $hasNode

@return NodeTranslation
357904
public function getNodeTranslationFor(HasNodeInterface $hasNode)
    {
        /* @var NodeVersion $nodeVersion */
        $nodeVersion = $this->getEntityManager()
            ->getRepository('KunstmaanNodeBundle:NodeVersion')
            ->getNodeVersionFor($hasNode);

        if (!is_null($nodeVersion)) {
            return $nodeVersion->getNodeTranslation();
        }

        return null;
    }
793787
public function getTranslation($locale = 'en_US', ConnectionInterface $con = null)
    {
        if (!isset($this->currentTranslations[$locale])) {
            if (null !== $this->collFeatureTypeI18ns) {
                foreach ($this->collFeatureTypeI18ns as $translation) {
                    if ($translation->getLocale() == $locale) {
                        $this->currentTranslations[$locale] = $translation;

                        return $translation;
                    }
                }
            }
            if ($this->isNew()) {
                $translation = new ChildFeatureTypeI18n();
                $translation->setLocale($locale);
            } else {
                $translation = ChildFeatureTypeI18nQuery::create()
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
                    ->findOneOrCreate($con);
                $this->currentTranslations[$locale] = $translation;
            }
            $this->addFeatureTypeI18n($translation);
        }

        return $this->currentTranslations[$locale];
    }
1023477
public function hasOne($hasOne = null)
    {
        if ($hasOne === null)
        {
            return $this->_hasOne;
        }
        $this->_hasOne = $hasOne;

        return $this;
    }
127746
public function createDraftVersion(
        HasNodeInterface $page,
        NodeTranslation $nodeTranslation,
        NodeVersion $nodeVersion
    ) {
        $user = $this->getAdminUser();
        $publicPage = $this->cloneHelper->deepCloneAndSave($page);

        /* @var NodeVersion $publicNodeVersion */
        $publicNodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')
            ->createNodeVersionFor(
                $publicPage,
                $nodeTranslation,
                $user,
                $nodeVersion->getOrigin(),
                NodeVersion::PUBLIC_VERSION,
                $nodeVersion->getCreated()
            );

        $nodeTranslation->setPublicNodeVersion($publicNodeVersion);
        $nodeVersion->setType(NodeVersion::DRAFT_VERSION);
        $nodeVersion->setOrigin($publicNodeVersion);
        $nodeVersion->setCreated(new \DateTime());

        $this->em->persist($nodeTranslation);
        $this->em->persist($nodeVersion);
        $this->em->flush();

        $this->eventDispatcher->dispatch(
            Events::CREATE_DRAFT_VERSION,
            new NodeEvent(
                $nodeTranslation->getNode(),
                $nodeTranslation,
                $nodeVersion,
                $page
            )
        );

        return $nodeVersion;
    }
1201681
protected function getBaseSelectString(LocaleEntity $locale, $withPlaces, $excludeUntranslatedStrings)
    {
        $cn = $this->app->make(EntityManager::class)->getConnection();
        $queryLocaleID = $cn->quote($locale->getID());

        $result = '
            select
                CommunityTranslationTranslatables.id,
                CommunityTranslationTranslatables.context,
                CommunityTranslationTranslatables.text,
                CommunityTranslationTranslatables.plural,
        ';
        if ($withPlaces) {
            $result .= '
                CommunityTranslationTranslatablePlaces.locations,
                CommunityTranslationTranslatablePlaces.comments,
            ';
        } else {
            $result .= "
                'a:0:{}' as locations,
                'a:0:{}' as comments,
            ";
        }
        $result .= '
                CommunityTranslationTranslations.approved,
                CommunityTranslationTranslations.text0,
                CommunityTranslationTranslations.text1,
                CommunityTranslationTranslations.text2,
                CommunityTranslationTranslations.text3,
                CommunityTranslationTranslations.text4,
                CommunityTranslationTranslations.text5
            from
                CommunityTranslationTranslatables
        ';
        if ($withPlaces) {
            $result .= '
                inner join CommunityTranslationTranslatablePlaces on CommunityTranslationTranslatables.id = CommunityTranslationTranslatablePlaces.translatable
            ';
        }
        $result .=
            ($excludeUntranslatedStrings ? 'inner join' : 'left join')
            . "
                CommunityTranslationTranslations on CommunityTranslationTranslatables.id = CommunityTranslationTranslations.translatable and 1 = CommunityTranslationTranslations.current and $queryLocaleID = CommunityTranslationTranslations.locale
            "
        ;

        return $result;
    }
833369
private function getNavigationContext(NodeInterface $node, $locale)
    {
        return $node->getPropertyValueWithDefault(
            sprintf(self::NAVIGATION_CONTEXT_PROPERTY, $locale),
            []
        );
    }
363666
public function getTranslation($locale = 'en_US', ConnectionInterface $con = null)
    {
        if (!isset($this->currentTranslations[$locale])) {
            if (null !== $this->collCustomerGroupI18ns) {
                foreach ($this->collCustomerGroupI18ns as $translation) {
                    if ($translation->getLocale() == $locale) {
                        $this->currentTranslations[$locale] = $translation;

                        return $translation;
                    }
                }
            }
            if ($this->isNew()) {
                $translation = new ChildCustomerGroupI18n();
                $translation->setLocale($locale);
            } else {
                $translation = ChildCustomerGroupI18nQuery::create()
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
                    ->findOneOrCreate($con);
                $this->currentTranslations[$locale] = $translation;
            }
            $this->addCustomerGroupI18n($translation);
        }

        return $this->currentTranslations[$locale];
    }
1127827
public function getTranslation($locale)
    {
        /** @var TaxClassTranslation $translation */
        foreach ($this->getTranslations() as $translation) {
            if ($translation->getLocale() === $locale) {
                return $translation;
            }
        }

        return null;
    }
1006623
protected function getTranslationOrNew($locale)
    {
        if (($translation = $this->getTranslation($locale)) === null) {
            $translation = $this->createNewTranslation($locale);
        }

        return $translation;
    }
1335587
public function getNewTranslation($locale)
    {
        $nodeSource = NodeSource::newWithType(
            $locale,
            $this->getNodeTypeName()
        );

        $this->translations->add($nodeSource);

        return $nodeSource;
    }
1255000
public function updatePage(
        Node $node,
        NodeTranslation $nodeTranslation,
        NodeVersion $nodeVersion,
        HasNodeInterface $page,
        $isStructureNode,
        TabPane $tabPane = null
    ) {
        $this->eventDispatcher->dispatch(
            Events::PRE_PERSIST,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );

        $nodeTranslation->setTitle($page->getTitle());
        if ($isStructureNode) {
            $nodeTranslation->setSlug('');
        }

        $nodeVersion->setUpdated(new \DateTime());
        if ($nodeVersion->getType() == NodeVersion::PUBLIC_VERSION) {
            $nodeTranslation->setUpdated($nodeVersion->getUpdated());
        }
        $this->em->persist($nodeTranslation);
        $this->em->persist($nodeVersion);
        $this->em->persist($node);
        if (null !== $tabPane) {
            $tabPane->persist($this->em);
        }
        $this->em->flush();

        $this->eventDispatcher->dispatch(
            Events::POST_PERSIST,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );

        return $nodeTranslation;
    }
118918
public function translate($locale = null)
    {
        if (!$locale) {
            $locale = \localizer\locale()->id();
        } else {
            $locale = (int)$locale;
        }

        return $this->getTranslation($locale);
    }
1157733
protected function findTranslationByLocale($locale, $withNewTranslations = true)
    {
        $translation = $this->getTranslations()->get($locale);

        if ($translation) {
            return $translation;
        }

        if ($withNewTranslations) {
            return $this->getNewTranslations()->get($locale);
        }
    }
138109
public function getByCode($sCode)
    {
        $aLanguages = $this->getAll();
        return !empty($aLanguages[$sCode]) ? $aLanguages[$sCode] : false;
    }
834764
public function getTranslations(LocaleEntity $locale, TranslatableEntity $translatable)
    {
        $numPlurals = $locale->getPluralCount();

        $result = [
            'current' => null,
            'others' => [],
        ];
        $translations = $this->app->make(TranslationRepository::class)->findBy(['translatable' => $translatable, 'locale' => $locale], ['createdOn' => 'DESC']);
        $dh = $this->app->make('helper/date');
        $uh = $this->app->make(UserService::class);
        foreach ($translations as $translation) {
            /* @var \CommunityTranslation\Entity\Translation $translation */
            $texts = [];
            switch (($translatable->getPlural() === '') ? 1 : $numPlurals) {
                case 6:
                    $texts[] = $translation->getText5();
                    /* @noinspection PhpMissingBreakStatementInspection */
                case 5:
                    $texts[] = $translation->getText4();
                    /* @noinspection PhpMissingBreakStatementInspection */
                case 4:
                    $texts[] = $translation->getText3();
                    /* @noinspection PhpMissingBreakStatementInspection */
                case 3:
                    $texts[] = $translation->getText2();
                    /* @noinspection PhpMissingBreakStatementInspection */
                case 2:
                    $texts[] = $translation->getText1();
                    /* @noinspection PhpMissingBreakStatementInspection */
                case 1:
                default:
                    $texts[] = $translation->getText0();
                    break;
            }
            $item = [
                'id' => $translation->getID(),
                'createdOn' => $dh->formatPrettyDateTime($translation->getCreatedOn(), false, true),
                'createdBy' => $uh->format($translation->getCreatedBy()),
                'approved' => $translation->isApproved(),
                'translations' => array_reverse($texts),
            ];
            if ($translation->isCurrent()) {
                $item['currentSince'] = $dh->formatPrettyDateTime($translation->getCurrentSince(), false, true);
                $result['current'] = $item;
            } else {
                $result['others'][] = $item;
            }
        }

        return $result;
    }
247055
public function getByLocale(LocaleEntity $locale)
    {
        $app = Application::getFacadeApplication();
        $result = $this->find($locale);
        if ($result === null) {
            $em = $this->getEntityManager();
            try {
                $numTranslatable = (int) $app->make(TranslatableRepository::class)
                    ->createQueryBuilder('t')
                        ->select('count(t.id)')
                        ->getQuery()->getSingleScalarResult();
            } catch (NoResultException $x) {
                $numTranslatable = 0;
            }
            if ($numTranslatable === 0) {
                $numApprovedTranslations = 0;
            } else {
                try {
                    $numApprovedTranslations = (int) $app->make(TranslationRepository::class)
                    ->createQueryBuilder('t')
                        ->select('count(t.id)')
                        ->where('t.locale = :locale')->setParameter('locale', $locale)
                        ->andWhere('t.current = 1')
                        ->getQuery()->getSingleScalarResult();
                } catch (NoResultException $x) {
                    $numApprovedTranslations = 0;
                }
            }
            $result = LocaleStatsEntity::create($locale, $numTranslatable, $numApprovedTranslations);
            $em->persist($result);
            $em->flush($result);
        }

        return $result;
    }
693324
public function getTranslations($localeCode)
    {
        $locale = $this->getLocaleByCode($localeCode);

        if (!$locale->hasPoFile()) {
            throw new Exception(sprintf(__("The project has never been scanned for %s.", 'strata'), $locale->getNativeLabel()));
        }

        return Translations::fromPoFile($locale->getPoFilePath());
    }