src/Graviton/I18nBundle/Service/I18nUtils.php
public function findMatchingTranslatables($value, $sourceLocale, $useWildCard = false)
    {
        // i need to use a queryBuilder as the repository doesn't let me do regex queries (i guess so..)
        $builder = $this->manager->createQueryBuilder(Translation::class);
        $builder
            ->field('language')->equals($sourceLocale);

        if ($useWildCard === true) {
            $value = new \MongoRegex($value);
        }

        /*
         * we have 2 cases to match
         * - 'translated' is set and matches
         * - 'translated' is not present, so 'original' can match (as this is inserted 'virtually')
         */
        $builder->addAnd(
            $builder->expr()
                ->addOr(
                    $builder->expr()->field('localized')->equals($value)
                )
                ->addOr(
                    $builder->expr()
                        ->field('localized')->equals(null)
                        ->field('original')->equals($value)
                )
        );

        $query = $builder->getQuery();

        return $query->execute()->toArray();
    }
public function findMatchingTranslatables($value, $sourceLocale, $useWildCard = false)
    {
        // i need to use a queryBuilder as the repository doesn't let me do regex queries (i guess so..)
        $builder = $this->manager->createQueryBuilder(Translation::class);
        $builder
            ->field('language')->equals($sourceLocale);

        if ($useWildCard === true) {
            $value = new \MongoRegex($value);
        }

        /*
         * we have 2 cases to match
         * - 'translated' is set and matches
         * - 'translated' is not present, so 'original' can match (as this is inserted 'virtually')
         */
        $builder->addAnd(
            $builder->expr()
                ->addOr(
                    $builder->expr()->field('localized')->equals($value)
                )
                ->addOr(
                    $builder->expr()
                        ->field('localized')->equals(null)
                        ->field('original')->equals($value)
                )
        );

        $query = $builder->getQuery();

        return $query->execute()->toArray();
    }
public function findMatchingTranslatables ( $ value , $ sourceLocale , $ useWildCard = false ) { // i need to use a queryBuilder as the repository doesn't let me do regex queries (i guess so..) $ builder = $ this -> manager -> createQueryBuilder ( Translation :: class ) ; $ builder -> field ( 'language' ) -> equals ( $ sourceLocale ) ; if ( $ useWildCard === true ) { $ value = new \ MongoRegex ( $ value ) ; } /*
         * we have 2 cases to match
         * - 'translated' is set and matches
         * - 'translated' is not present, so 'original' can match (as this is inserted 'virtually')
         */ $ builder -> addAnd ( $ builder -> expr ( ) -> addOr ( $ builder -> expr ( ) -> field ( 'localized' ) -> equals ( $ value ) ) -> addOr ( $ builder -> expr ( ) -> field ( 'localized' ) -> equals ( null ) -> field ( 'original' ) -> equals ( $ value ) ) ) ; $ query = $ builder -> getQuery ( ) ; return $ query -> execute ( ) -> toArray ( ) ; }
This function allows to search for existing translations from a source
language, probably using a wildcard

@param string  $value        the translated string
@param string  $sourceLocale a source locale
@param boolean $useWildCard  if we should search wildcard or not

@return array matching Translatables
This function allows to search for existing translations from a source language probably using a wildcard