@param LocaleEntity $locale
@param mixed $user
@param LocaleEntity[]|null $approvedLocales

@return \CommunityTranslation\TranslationsConverter\ConverterInterface[]
517472
private function getAllowedDownloadFormats(LocaleEntity $locale, $user = 'current', array $approvedLocales = null)
    {
        $result = [];
        $allowedFormats = [];
        if ($this->allowedDownloadFormats) {
            $tcProvider = $this->app->make(TranslationsConverterProvider::class);
            foreach (explode(',', $this->allowedDownloadFormats) as $adf) {
                $converter = $tcProvider->getByHandle($adf);
                if ($converter !== null && $converter->canSerializeTranslations()) {
                    $allowedFormats[$adf] = $converter;
                }
            }
        }
        if (!empty($allowedFormats)) {
            $userOk = false;
            switch ($this->allowedDownloadFor) {
                case static::ALLOWDOWNLOADFOR_EVERYBODY:
                    $userOk = true;
                    break;
                case static::ALLOWDOWNLOADFOR_REGISTEREDUSERS:
                    if ($user === 'current') {
                        $user = $this->getAccess()->getUser('current');
                    }
                    if ($user !== null) {
                        $userOk = true;
                    }
                    break;
                case static::ALLOWDOWNLOADFOR_TRANSLATORS_ALLLOCALES:
                    if ($approvedLocales === null) {
                        $approvedLocales = $this->app->make(LocaleRepository::class)->getApprovedLocales();
                    }
                    if ($user === 'current') {
                        $user = $this->getAccess()->getUser('current');
                    }
                    foreach ($approvedLocales as $l) {
                        if ($this->getAccess()->getLocaleAccess($l, $user) >= Access::TRANSLATE) {
                            $userOk = true;
                            break;
                        }
                    }
                    break;
                case static::ALLOWDOWNLOADFOR_TRANSLATORS_OWNLOCALES:
                    if ($this->getAccess()->getLocaleAccess($locale, $user) >= Access::TRANSLATE) {
                        $userOk = true;
                    }
                    break;
                case static::ALLOWDOWNLOADFOR_LOCALEADMINS_ALLLOCALES:
                    if ($approvedLocales === null) {
                        $approvedLocales = $this->app->make(LocaleRepository::class)->getApprovedLocales();
                    }
                    if ($user === 'current') {
                        $user = $this->getAccess()->getUser('current');
                    }
                    foreach ($approvedLocales as $l) {
                        if ($this->getAccess()->getLocaleAccess($l, $user) >= Access::ADMIN) {
                            $userOk = true;
                            break;
                        }
                    }
                    break;
                case static::ALLOWDOWNLOADFOR_LOCALEADMINS_OWNLOCALES:
                    if ($this->getAccess()->getLocaleAccess($locale, $user) >= Access::TRANSLATE) {
                        $userOk = true;
                    }
                    break;
                case static::ALLOWDOWNLOADFOR_GLOBALADMINS:
                    if ($this->getAccess()->getLocaleAccess($locale, $user) >= Access::GLOBAL_ADMIN) {
                        $userOk = true;
                    }
                    break;
            }
            if ($userOk === true) {
                $result = $allowedFormats;
            }
        }

        return $result;
    }
420457
public function findByStatusIdAndUser($locale, $statusId, $user, $limit = null)
    {
        return $this->orderRepository->findByStatusIdAndUser(
            $locale,
            $statusId,
            $user,
            $limit
        );
    }
644693
public function findFiltersForUserAndContext($context, $userId, $locale)
    {
        $filters = $this->filterRepository->findByUserAndContextAndLocale($locale, $context, $userId);
        array_walk(
            $filters,
            function(&$filter) use ($locale) {
                $filter = new Filter($filter, $locale);
            }
        );

        return $filters;
    }
1360801
protected function buildInitialTranslations(LocaleEntity $locale, \Concrete\Core\Database\Driver\PDOStatement $rs)
    {
        $approvedSupport = $this->app->make(Access::class)->getLocaleAccess($locale) >= Access::ADMIN;
        $result = [];
        $numPlurals = $locale->getPluralCount();
        while (($row = $rs->fetch()) !== false) {
            $item = [
                'id' => (int) $row['id'],
                'original' => $row['text'],
            ];
            if ($approvedSupport && $row['approved']) {
                $item['isApproved'] = true;
            }
            if ($row['context'] !== '') {
                $item['context'] = $row['context'];
            }
            $isPlural = $row['plural'] !== '';
            if ($isPlural) {
                $item['originalPlural'] = $row['plural'];
            }
            if ($row['text0'] !== null) {
                $translations = [];
                switch ($isPlural ? $numPlurals : 1) {
                    case 6:
                        $translations[] = $row['text5'];
                        /* @noinspection PhpMissingBreakStatementInspection */
                    case 5:
                        $translations[] = $row['text4'];
                        /* @noinspection PhpMissingBreakStatementInspection */
                    case 4:
                        $translations[] = $row['text3'];
                        /* @noinspection PhpMissingBreakStatementInspection */
                    case 3:
                        $translations[] = $row['text2'];
                        /* @noinspection PhpMissingBreakStatementInspection */
                    case 2:
                        $translations[] = $row['text1'];
                        /* @noinspection PhpMissingBreakStatementInspection */
                    case 1:
                        $translations[] = $row['text0'];
                        break;
                }
                $item['translations'] = array_reverse($translations);
            }
            $result[] = $item;
        }
        $rs->closeCursor();

        return $result;
    }
975492
private function createLocale($localeID, $notes, $approve)
    {
        $locale = LocaleEntity::create($localeID)
            ->setRequestedBy($this->getAccess()->getUserEntity('current'))
            ->setRequestedOn(new DateTime())
            ->setIsApproved($approve)
        ;
        $em = $this->app->make(EntityManager::class);
        $em->persist($locale);
        $em->flush($locale);
        if (!$approve) {
            $this->app->make(NotificationRepository::class)->newLocaleRequested($locale, $notes);
        }

        return $locale;
    }
777456
protected function parseLocale($locale)
	{
		if ( ! is_null($locale))
		{
			return array_filter(array($locale, $this->fallback));
		}
		else
		{
			return array_filter(array($this->locale, $this->fallback));
		}
	}
35391
public function getDisplayedAuthors( $locale = self::FALLBACK_LOCALE )
    {
        $result = array();
        $mapper = $this->getMapper();

        foreach ( $this->authors as $author )
        {
            if ( $mapper && ! empty( $author['email'] ) &&
                 ( $user = $mapper->getUserByEmail( $author['email'] ) ) )
            {
                $insert = array(
                    'name' => $user->displayName,
                    'url'  => '/app/' . $locale . '/user/view/' . rawurlencode( $user->displayName ),
                );
            }
            else if ( ! empty( $author['name'] ) || ! empty( $author['email'] ) )
            {
                $insert = array(
                    'name' => isset( $author['name'] )
                            ? $author['name']
                            : strstr( $author['email'], '@', true ),
                    'url'  => isset( $author['homepage'] )
                            ? $author['homepage']
                            : null,
                );
            }
            else
            {
                continue;
            }

            $result[] = $insert;
        }

        return $result;
    }
338915
public function forLocale($locale, $fallbacks=null)
    {
        $fork = $this->replicate()->setLocale($locale);

        if ($fallbacks) {
            return $fork->setFallbacks($fallbacks);
        }

        if ($this->localeFallbacks) {
            return $fork->setFallbacks($this->localeFallbacks);
        }

        return $fork;
    }
280031
protected function unsetTranslationFromEditor($access, LocaleEntity $locale, TranslatableEntity $translatable)
    {
        $currentTranslation = $this->app->make(TranslationRepository::class)->findOneBy([
            'locale' => $locale,
            'translatable' => $translatable,
            'current' => true,
        ]);
        if ($currentTranslation !== null) {
            /* @var TranslationEntity $currentTranslation */
            $em = $this->getEntityManager();
            if ($currentTranslation->isApproved() && $access < Access::ADMIN) {
                throw new UserMessageException(t("The current translation is marked as reviewed, so you can't remove it."));
            }
            $currentTranslation->setIsCurrent(false);
            $em->persist($currentTranslation);
            $em->flush();
            $this->app->make(StatsRepository::class)->resetForTranslation($currentTranslation);
            $result = $this->app->make(Editor::class)->getTranslations($locale, $translatable);
        } else {
            $result = [];
        }

        return $this->app->make(ResponseFactoryInterface::class)->json($result);
    }
1357199
protected function buildTranslations(LocaleEntity $locale, PDOStatement $rs)
    {
        $translations = new Translations();
        $translations->setLanguage($locale->getID());
        $numPlurals = $locale->getPluralCount();
        while (($row = $rs->fetch()) !== false) {
            $translation = new \Gettext\Translation($row['context'], $row['text'], $row['plural']);
            foreach (unserialize($row['locations']) as $location) {
                $translation->addReference($location);
            }
            foreach (unserialize($row['comments']) as $comment) {
                $translation->addExtractedComment($comment);
            }
            if ($row['text0'] !== null) {
                if (!$row['approved']) {
                    $translation->addFlag('fuzzy');
                }
                $translation->setTranslation($row['text0']);
                if ($translation->hasPlural()) {
                    switch ($numPlurals) {
                        case 6:
                            $translation->setPluralTranslation($row['text5'], 4);
                            /* @noinspection PhpMissingBreakStatementInspection */
                        case 5:
                            $translation->setPluralTranslation($row['text4'], 3);
                            /* @noinspection PhpMissingBreakStatementInspection */
                        case 4:
                            $translation->setPluralTranslation($row['text3'], 2);
                            /* @noinspection PhpMissingBreakStatementInspection */
                        case 3:
                            $translation->setPluralTranslation($row['text2'], 1);
                            /* @noinspection PhpMissingBreakStatementInspection */
                        case 2:
                            $translation->setPluralTranslation($row['text1'], 0);
                            /* @noinspection PhpMissingBreakStatementInspection */
                            break;
                    }
                }
            }
            $translations->append($translation);
        }
        $rs->closeCursor();

        return $translations;
    }
1171408
public function findAllByLocale($locale, $filter = array())
    {
        if (empty($filter)) {
            $order = $this->orderRepository->findAllByLocale($locale);
        } else {
            $order = $this->orderRepository->findByLocaleAndFilter($locale, $filter);
        }

        if ($order) {
            array_walk(
                $order,
                function (&$order) use ($locale) {
                    $order = $this->orderFactory->createApiEntity($order, $locale);
                    $this->updateApiEntity($order, $locale);
                }
            );
        }

        return $order;
    }
307103
public function changeLocale(Request $request, $locale)
    {
        if (($token = $this->tokenStorage->getToken()) && $token->getUser() !== 'anon.') {
            $this->localeManager->setUserLocale($locale);
        }
        $request->getSession()->set('_locale', $locale);

        return new Response('Locale changed to ' . $locale, 200);
    }
1034771
public function findAllByLocale($locale, $filter = array())
    {
        if (empty($filter)) {
            $items = $this->itemRepository->findAllByLocale($locale);
        } else {
            $items = $this->itemRepository->findByLocaleAndFilter($locale, $filter);
        }

        array_walk(
            $items,
            function (&$item) use ($locale) {
                $item = $this->itemFactory->createApiEntity($item, $locale);
            }
        );

        return $items;
    }
53234
public function findUsagesByLocales( $locale = null )
    {
        if ( empty( $locale ) )
        {
            $locale = $this->getLocale();
        }

        return $this->getMapper()
                    ->findUsagesByLocales( (array) $locale );
    }
1225898
public function findByStatusIdsAndUser($locale, $statusIds, UserInterface $user, $limit = null)
    {
        try {
            $qb = $this->getOrderQuery($locale)
                ->andWhere('o.creator = :user')
                ->setParameter('user', $user)
                ->andWhere('status.id IN (:statusId)')
                ->setParameter('statusId', $statusIds)
                ->orderBy('o.created', 'DESC')
                ->setMaxResults($limit);

            return $qb->getQuery()->getResult();
        } catch (NoResultException $exc) {
            return null;
        }
    }
369208
public function switchLocale($locale)
    {
        if (in_array($locale, $this->config['locales'])) {
            app('session')->put('administrator_locale', $locale);
        }

        return redirect()->back();
    }
873119
protected function getLocales($obj)
    {
        $result = [];
        if ($obj instanceof LocaleEntity) {
            $result[] = $obj;
        } elseif (is_string($obj)) {
            $app = Application::getFacadeApplication();
            $l = $app->make(LocaleRepository::class)->findApproved($obj);
            if ($l === null) {
                throw new UserMessageException(t('Invalid locale specified'));
            }
            $result[] = $l;
        } elseif (is_array($obj)) {
            foreach ($obj as $item) {
                $result = array_merge($result, $this->getLocales($item));
            }
        }
        if (empty($result)) {
            throw new UserMessageException(t('Invalid locale specified'));
        }

        return $result;
    }