{@inheritdoc}

Join document with translation children, and filter on the right child
node.
438379
public function alterQueryForTranslation(
        QueryObjectModelFactoryInterface $qomf,
        SourceInterface &$selector,
        ConstraintInterface &$constraint = null,
        $alias,
        $locale
    ) {
        $childAlias = "_{$locale}_{$alias}";

        $selector = $qomf->join(
            $selector,
            $qomf->selector($childAlias, 'nt:base'),
            QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_RIGHT_OUTER,
            $qomf->childNodeJoinCondition($childAlias, $alias)
        );

        $languageConstraint = $qomf->comparison(
            $qomf->nodeName($childAlias),
            QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
            $qomf->literal(Translation::LOCALE_NAMESPACE.":$locale")
        );

        if ($constraint) {
            $constraint = $qomf->andConstraint(
                $constraint,
                $languageConstraint
            );
        } else {
            $constraint = $languageConstraint;
        }
    }
392062
public static Node addChildNode(Document doc, Node parentNode, String childName, String childValue){
                if(doc == null || parentNode == null || childName == null){
                        return null;
                }
                Node childNode = doc.createElement(childName);
                if(childValue != null){
                        childNode.setTextContent(childValue);
                }
                parentNode.appendChild(childNode);
                return childNode;
        }
581731
function(filter){
      filter = filter || this.filter;

      var cursor = this.cursor_;
      var prevSibling = this.c; // previous sibling
      var prevChild = this.d;   // previous child

      do
      {
        var node = cursor ? cursor[prevSibling] : this.root_[prevChild];
        if (node)
        {
          while (node[prevChild])
            node = node[prevChild];
          cursor = node;
        }
        else
          if (cursor)
            cursor = cursor[PARENT_NODE];

        if (!cursor || cursor === this.root_)
        {
          cursor = null;
          break;
        }
      }
      while (!filter(cursor));

      return this.cursor_ = cursor;
    }
1173170
private function cascadePersist($document, array &$visited)
    {
        $class = $this->dm->getClassMetadata(get_class($document));

        foreach ($class->associationMappings as $fieldName => $mapping) {
            if ( ! $mapping['isCascadePersist']) {
                continue;
            }

            $relatedDocuments = $class->reflFields[$fieldName]->getValue($document);

            if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) {
                if ($relatedDocuments instanceof PersistentCollection) {
                    // Unwrap so that foreach() does not initialize
                    $relatedDocuments = $relatedDocuments->unwrap();
                }

                foreach ($relatedDocuments as $relatedDocument) {
                    $this->doPersist($relatedDocument, $visited);
                }
            } elseif ($relatedDocuments !== null) {
                $this->doPersist($relatedDocuments, $visited);
            }
        }
    }
148881
function processChildrenOnce( &$textElements, &$children, $tpl, $rootNamespace, $name )
    {
        foreach ( array_keys( $children ) as $childKey )
        {
            $child =& $children[$childKey];
            $tpl->processNode( $child, $textElements, $rootNamespace, $name );
        }
        return true;
    }
229106
function translate(content, langFile) {
  return content.replace(templateRegEx, function (match, capture) {
    return (0, _lodash2.default)(langMap.get(langFile), capture);
  });
}
1164821
private function loadNodeAndAncestors($uuid, $webspaceKey, $locale, $excludeGhosts, $excludeShadows, $complete)
    {
        $descendants = $this->getMapper()->loadNodeAndAncestors(
            $uuid,
            $locale,
            $webspaceKey,
            $excludeGhosts,
            $excludeShadows
        );
        $descendants = array_reverse($descendants);

        $childTiers = [];
        foreach ($descendants as $descendant) {
            foreach ($descendant->getChildren() as $child) {
                $type = $child->getType();

                if ($excludeShadows && null !== $type && 'shadow' === $type->getName()) {
                    continue;
                }

                if ($excludeGhosts && null !== $type && 'ghost' === $type->getName()) {
                    continue;
                }

                if (!isset($childTiers[$descendant->getUuid()])) {
                    $childTiers[$descendant->getUuid()] = [];
                }
                $childTiers[$descendant->getUuid()][] = $this->prepareNode(
                    $child,
                    $webspaceKey,
                    $locale,
                    1,
                    $complete,
                    $excludeGhosts
                );
            }
        }
        $result = array_shift($childTiers);

        $this->iterateTiers($childTiers, $result);

        return $result;
    }
255905
function (scope, predicate) {
      var result = [];
      var dom = scope.dom();
      var children = Arr.map(dom.childNodes, Element.fromDom);

      Arr.each(children, function (x) {
        if (predicate(x)) {
          result = result.concat([ x ]);
        }
        result = result.concat(filterDescendants(x, predicate));
      });
      return result;
    }
1286692
@Nullable
  private static Node getNode(Document doc, String parentNodeName, String targetNodeName) {
    NodeList parentElements = doc.getElementsByTagNameNS(APP_ENGINE_NAMESPACE, parentNodeName);
    if (parentElements.getLength() > 0) {
      Node parent = parentElements.item(0);
      if (parent.hasChildNodes()) {
        for (int i = 0; i < parent.getChildNodes().getLength(); i++) {
          Node child = parent.getChildNodes().item(i);
          if (child.getNodeName().equals(targetNodeName)) {
            return child;
          }
        }
      }
    }
    return null;
  }
924426
private function doRemoveAllTranslations($document, ClassMetadata $metadata)
    {
        if (!$this->isDocumentTranslatable($metadata)) {
            return;
        }

        $node = $this->session->getNode($this->getDocumentId($document));
        $strategy = $this->dm->getTranslationStrategy($metadata->translator);
        $strategy->removeAllTranslations($document, $node, $metadata);
    }
635504
function translateFragment(element) {
    element = element || document.documentElement;

    // check all translatable children (= w/ a `data-l10n-id' attribute)
    var children = getTranslatableChildren(element);
    var elementCount = children.length;
    for (var i = 0; i < elementCount; i++) {
      translateElement(children[i]);
    }

    // translate element itself if necessary
    translateElement(element);
  }
761069
public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null)
    {
        $sortColumn = isset($filters['sidx']) ? $filters['sidx'] : 'id';
        $order = isset($filters['sord']) ? $filters['sord'] : 'ASC';

        $builder = $this->createQueryBuilder()
            ->hydrate(false)
            ->select('id');

        $this->addTransUnitFilters($builder, $filters);
        $this->addTranslationFilter($builder, $locales, $filters);

        $results = $builder->sort($sortColumn, $order)
            ->skip($rows * ($page - 1))
            ->limit($rows)
            ->getQuery()
            ->execute();

        $ids = array();
        foreach ($results as $result) {
            $ids[] = $result['_id'];
        }

        $transUnits = array();

        if (count($ids) < 1) {
            return $transUnits;
        }

        $results = $this->createQueryBuilder()
            ->hydrate(false)
            ->field('id')->in($ids)
            ->field('translations.locale')->in($locales)
            ->sort(array($sortColumn => $order, 'translations.locale' => 'asc'))
            ->getQuery()
            ->execute();

        foreach ($results as $item) {
            $end = count($item['translations']);
            for ($i = 0; $i < $end; $i++) {
                if (!in_array($item['translations'][$i]['locale'], $locales)) {
                    unset($item['translations'][$i]);
                }
            }
            sort($item['translations']);
            $transUnits[] = $item;
        }

        return $transUnits;
    }
1201303
public static function parse($content, Document $document = null, &$offset = 0)
    {
        if (preg_match('/^\s*\[(?P<array>.*)/is', $content, $match)) {
            preg_match_all('/(.*?)(\[|\])/s', trim($content), $matches);

            $level = 0;
            $sub   = '';
            foreach ($matches[0] as $part) {
                $sub .= $part;
                $level += (strpos($part, '[') !== false ? 1 : -1);
                if ($level <= 0) {
                    break;
                }
            }

            // Removes 1 level [ and ].
            $sub        = substr(trim($sub), 1, -1);
            $sub_offset = 0;
            $values     = Element::parse($sub, $document, $sub_offset, true);

            $offset += strpos($content, '[') + 1;
            // Find next ']' position
            $offset += strlen($sub) + 1;

            return new self($values, $document);
        }

        return false;
    }
258550
def joinStringsInList(literalEntities, prefLanguage="en"):
    
    match = []

    if len(literalEntities) == 1:
        return literalEntities[0]
    elif len(literalEntities) > 1:
        for x in literalEntities:
            if getattr(x, 'language') and getattr(x,
                                                  'language') == prefLanguage:
                match.append(x)
        if not match:  # don't bother about language
            for x in literalEntities:
                match.append(x)

    return " - ".join([x for x in match])
134551
@Deprecated
    private static boolean doesElementContainTranslatableContentV1(final Node node) {
        final NodeList children = node.getChildNodes();
        if (children != null) {
            /* check to see if any of the children are translatable nodes */
            for (int j = 0; j < children.getLength(); ++j) {
                final Node child = children.item(j);
                final String childName = child.getNodeName();

                /* this child node is itself translatable, so return true */
                if (TRANSLATABLE_ELEMENTS_OLD.contains(childName)) return true;
            }

            /*
             * now check to see if any of the child have children that are translatable
             */
            for (int j = 0; j < children.getLength(); ++j) {
                final Node child = children.item(j);
                final NodeList grandChildren = child.getChildNodes();
                for (int k = 0; k < grandChildren.getLength(); ++k) {
                    final Node grandChild = grandChildren.item(k);
                    final boolean result = doesElementContainTranslatableContentV1(grandChild);
                    if (result) return true;
                }
            }
        }

        return false;
    }
352410
function processChildren( &$textElements,
                              &$children, $key, &$item, &$index, &$isFirstRun,
                              &$delimiterStructure, &$sequenceStructure, &$filterStructure,
                              $tpl, $rootNamespace, $name, $functionPlacement,
                              &$variableIterator, $noLastValue,
                              &$iteratorData )
    {
        if ( $variableIterator !== null )
        {
            unset( $last );
            if ( !$noLastValue and $iteratorData['iterator'] !== false )
            {
                $last =& $iteratorData['iterator'];
            }
            else
            {
                $last = false;
            }
            unset( $iteratorData['iterator'] );
            $iteratorData['iterator'] = new eZTemplateSectionIterator();
            $iteratorData['iterator']->setIteratorValues( $item, $key, $index, $index + 1, false, $last );
            unset( $last );

            $iteratorObject =& $iteratorData['iterator'];
            $tpl->setVariable( $variableIterator, $iteratorObject, $name );
        }
        else
        {
            $tpl->setVariable( "key", $key, $name );
            $tpl->setVariable( "item", $item, $name );
            $tpl->setVariable( "index", $index, $name );
            $tpl->setVariable( "number", $index + 1, $name );
        }
        if ( count( $filterStructure ) > 0 )
        {
            $filterCount = count( $filterStructure );
            $includeElement = true;
            for ( $i = 0; $i < $filterCount; ++$i )
            {
                $filterElement =& $filterStructure[$i];
                $filterParameters =& $filterElement[3];
                $filterName = $filterElement[2];
                $filterMatch = null;
                if ( isset( $filterParameters["match"] ) )
                {
                    $filterMatch = $tpl->elementValue( $filterParameters["match"], $rootNamespace, $name, $functionPlacement );
                    if ( $filterMatch )
                        $includeElement = $filterName == "section-exclude" ? false : true;
                }
                else
                    $tpl->missingParameter( "section:$filterName", "match" );
            }
            if ( !$includeElement )
                return false;
        }
        if ( $delimiterStructure !== null and !$isFirstRun )
        {
            $delimiterParameters = $delimiterStructure[3];
            $delimiterMatch = true;
            if ( isset( $delimiterParameters["modulo"] ) )
            {
                $delimiterModulo = $delimiterParameters["modulo"];
                $modulo = $tpl->elementValue( $delimiterModulo, $rootNamespace, $name, $functionPlacement );
                $modulo = trim( $modulo );
                if ( is_numeric( $modulo ) )
                    $delimiterMatch = ( $index % $modulo ) == 0;
            }
            if ( isset( $delimiterParameters["match"] ) )
            {
                $delimiterMatchParameter = $delimiterParameters["match"];
                $delimiterMatch = $tpl->elementValue( $delimiterMatchParameter, $rootNamespace, $name, $functionPlacement );
            }
            if ( $delimiterMatch )
            {
                $delimiterChildren =& $delimiterStructure[1];
                if ( is_array( $delimiterChildren ) )
                {
                    foreach ( array_keys( $delimiterChildren ) as $delimiterChildKey )
                    {
                        $delimiterChild =& $delimiterChildren[$delimiterChildKey];
                        $tpl->processNode( $delimiterChild, $textElements, $rootNamespace, $name );
                    }
                }
            }
        }
        $isFirstRun = false;
        if ( $sequenceStructure !== null and is_array( $sequenceStructure ) )
        {
            $sequenceValue = array_shift( $sequenceStructure );
            if ( $variableIterator !== null )
            {
                $iteratorData['iterator']->setSequence( $sequenceValue );
            }
            else
            {
                $tpl->setVariable( "sequence", $sequenceValue, $name );
            }
            $sequenceStructure[] = $sequenceValue;
        }
        foreach ( array_keys( $children ) as $childKey )
        {
            $child =& $children[$childKey];
            $tpl->processNode( $child, $textElements, $rootNamespace, $name );
        }
        ++$index;
        return true;
    }
1077362
public function orderAt($uuid, $position, $userId, $webspaceKey, $locale)
    {
        $document = $this->documentManager->find($uuid, $locale);

        $parentDocument = $this->inspector->getParent($document);
        $siblingDocuments = $this->inspector->getChildren($parentDocument);

        $siblings = array_values($siblingDocuments->toArray()); // get indexed array
        $countSiblings = count($siblings);
        $currentPosition = array_search($document, $siblings) + 1;

        if ($countSiblings < $position || $position <= 0) {
            throw new InvalidOrderPositionException(
                sprintf(
                    'Cannot order node "%s" at out-of-range position "%s", must be >= 0 && < %d"',
                    $this->inspector->getPath($document),
                    $position,
                    $countSiblings
                )
            );
        }

        if ($position === $countSiblings) {
            // move to the end
            $this->documentManager->reorder($document, null);
        } else {
            if ($currentPosition < $position) {
                $targetSibling = $siblings[$position];
            } elseif ($currentPosition > $position) {
                $targetSibling = $siblings[$position - 1];
            }

            $this->documentManager->reorder($document, $targetSibling->getUuid());
        }

        $this->documentManager->flush();

        return $this->documentToStructure($document);
    }