@param int $access
@param TranslationEntity $translation

@throws UserMessageException

@return \Symfony\Component\HttpFoundation\Response
340853
protected function denyTranslation($access, TranslationEntity $translation)
    {
        if ($access < Access::ADMIN) {
            throw new UserMessageException(t('Access denied'));
        }
        if ($translation->isCurrent()) {
            throw new UserMessageException(t('The selected translation is already the current one'));
        }
        $em = $this->getEntityManager();
        $translation->setIsApproved(false);
        $em->persist($translation);
        $em->flush();

        $result = $this->app->make(Editor::class)->getTranslations($translation->getLocale(), $translation->getTranslatable());
        unset($result['current']);

        return $this->app->make(ResponseFactoryInterface::class)->json($result);
    }
642217
public function update(Translation $translation, FormRequest $request)
    {
        $this->repository->update($request->id, $request->all());

        return $this->redirect($request, $translation);
    }
797892
public function handle(Guard $auth, Dispatcher $event, Translator $translator)
    {
        if (! $auth->attempt($this->credentials, $this->remember)) {
            $event->fire(new UserLoginHasFailed($auth->user()));
            throw new LoginFailed($translator->get('authentication::session.creation_failed'));
        }

        $user = $auth->user();
        if ($user->isBanned()) {
            $auth->logout();
            throw new UserIsBanned($translator->get('authentication::user.banned', ['email' => $user->email]));
        }

        $event->fire(new UserHasLoggedIn($user));
    }
643677
public function unPublish(NodeTranslation $nodeTranslation)
    {
        if (false === $this->authorizationChecker->isGranted(PermissionMap::PERMISSION_UNPUBLISH, $nodeTranslation->getNode())) {
            throw new AccessDeniedException();
        }

        $node = $nodeTranslation->getNode();
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
        $page = $nodeVersion->getRef($this->em);

        $this->eventDispatcher->dispatch(
            Events::PRE_UNPUBLISH,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );
        $nodeTranslation->setOnline(false);
        $this->em->persist($nodeTranslation);
        $this->em->flush();

        // Remove scheduled task
        $this->unSchedulePublish($nodeTranslation);

        $this->eventDispatcher->dispatch(
            Events::POST_UNPUBLISH,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );
    }
603962
public function show($id, $translationId)
    {
        $file = $this->getFile($id);
        if (!empty($file)) {
            $this->authorize('read', $file);
            $translation = $this->repository->getFileTranslationById($file, $translationId);
            if (!empty($translation)) {
                return $this->respondWithSuccess($translation, new FileTranslationTransformer);
            }
        }
        return $this->respondNotFound();
    }
225724
public function addTranslation(TranslationInterface $translation)
    {
        if (!$this->translations->contains($translation)) {
            $this->translations[$translation->getLocale()] = $translation;
            $translation->setTranslatable($this);
        }
    
        return $this;
    }
308156
protected function reuseTranslation($access, TranslationEntity $translation, UserEntity $user, $packageVersionID)
    {
        if ($translation->isCurrent()) {
            throw new UserMessageException(t('The selected translation is already the current one'));
        }

        $translationID = $translation->getID();
        $translations = $this->convertTranslationToGettext($translation, $access < Access::ADMIN);
        $importer = $this->app->make(Importer::class);
        $imported = $importer->import($translations, $translation->getLocale(), $user, ($access >= Access::ADMIN) ? ImportOptions::forAdministrators() : ImportOptions::forTranslators());
        $this->getEntityManager()->clear();
        $translation = $this->app->make(TranslationRepository::class)->find($translationID);
        if ($imported->newApprovalNeeded > 0) {
            $this->app->make(NotificationRepository::class)->translationsNeedApproval(
                $translation->getLocale(),
                $imported->newApprovalNeeded,
                $user->getUserID(),
                ($packageVersionID === self::PACKAGEVERSION_UNREVIEWED) ? null : $packageVersionID
             );
        }
        $result = $this->app->make(Editor::class)->getTranslations($translation->getLocale(), $translation->getTranslatable());
        if ($imported->newApprovalNeeded && !$imported->addedAsCurrent) {
            $result['message'] = t('Since the current translation is approved, you have to wait that this new translation will be approved');
        }
        if ($imported->addedNotAsCurrent || $imported->existingNotCurrentUntouched) {
            unset($result['current']);
        }

        return $this->app->make(ResponseFactoryInterface::class)->json($result);
    }
196249
static function createMessage( $context, $source, $comment = null, $translation = null )
    {
        $msg = array( "context" => $context,
                      "source" => $source,
                      "comment" => $comment,
                      "translation" => $translation );
        return $msg;
    }
67231
public function translate($key, $translation, $locale = null, $driver = null) {
        $driver = ! is_null($driver) ? $this->getDriver($driver) : $this->driver();

        return $driver->translate(
            $key, $translation, $locale
        );
    }
560213
public function getTranslations($locale, $domain)
    {
        $conn = $this->getEntityManager()->getConnection();
        $stmt = $conn->executeQuery(
            'SELECT m.message, t.translation FROM message m JOIN message_translation t ON (t.message_id = m.id AND t.locale = ? ) WHERE m.domain = ?',
            [$locale, $domain]
        );
        while ($row = $stmt->fetch()) {
            yield $row['message'] => $row['translation'];
        }
    }
1241510
public function addTranslationSelect(
        string $root,
        EntityDefinition $definition,
        QueryBuilder $query,
        Context $context
    ): void {
        $translationDefinition = $definition->getTranslationDefinition();

        $fields = $translationDefinition->getFields();
        $chain = self::buildTranslationChain($root, $context, $definition->isInheritanceAware() && $context->considerInheritance());

        /** @var TranslatedField $field */
        foreach ($fields as $field) {
            if (!$field instanceof StorageAware) {
                continue;
            }

            foreach ($chain as $tableAccessor) {
                $name = $field->getPropertyName();
                $query->addSelect(
                    self::escape($tableAccessor['alias']) . '.' . self::escape($field->getStorageName()) . ' as '
                    . self::escape($tableAccessor['alias'] . '.' . $name)
                );
            }

            //check if current field is a translated field of the origin definition
            $origin = $definition->getFields()->get($field->getPropertyName());
            if ($origin instanceof TranslatedField) {
                //add selection for resolved parent-child and language inheritance
                $query->addSelect(
                    $this->getTranslationFieldSelectExpr($field, $chain) . ' as '
                    . self::escape($root . '.' . $field->getPropertyName())
                );
            }
        }
    }
270847
public function saveTranslationsToFile(Translations $translations, $filename)
    {
        if (!$this->canSerializeTranslations()) {
            throw new UserMessageException(t('The "%s" converter is not able to serialize translations', $this->getName()));
        }
        $serialized = $this->convertTranslationsToString($translations);
        if (@$this->fs->put($filename, $serialized) === false) {
            throw new UserMessageException(t('Failed to save translations to file'));
        }
    }
96767
private function updateObjectTranslations(EntityManagerInterface $entityManager, $object): void
    {
        $translatableMeta = $this->getTranslatableMetadata($entityManager, $object);
        if (!$translatableMeta->hasTranslatableProperties()) {
            return;
        }

        foreach ($translatableMeta->getTranslationAssociationMetadatas() as $associationMeta) {
            $context = $this->getTranslationContext($entityManager, $associationMeta, $object);
            $locale = $this->translationHelper->getObjectLocale($context, $object);
            if (is_null($locale) || $locale === '') {
                $locale = $this->getLocale();
            }

            $hasTranslatedProperties = $this->translationHelper->hasTranslatedProperties($context, $object);
            if (!isset($locale) && $hasTranslatedProperties) {
                throw new Exception\RuntimeException(
                    "Neither object's locale nor the current locale was set for translatable properties"
                );
            }

            if ($hasTranslatedProperties) {
                $this->translationHelper->copyPropertiesToTranslation(
                    $context,
                    $object,
                    $locale
                );
            } else {
                $this->translationHelper->removeEmptyTranslation($context, $object);
            }
        }
    }
596651
public function messagePage(ServerRequestInterface $request, UserInterface $user): ResponseInterface
    {
        $referer = $request->getHeaderLine('referer');

        $body    = $request->get('body', '');
        $subject = $request->get('subject', '');
        $to      = $request->get('to', '');
        $url     = $request->get('url', $referer);

        $to_user = $this->user_service->findByUserName($to);

        if ($to_user === null || $to_user->getPreference('contactmethod') === 'none') {
            throw new AccessDeniedHttpException('Invalid contact user id');
        }

        $title = I18N::translate('Send a message');

        return $this->viewResponse('message-page', [
            'body'    => $body,
            'from'    => $user,
            'subject' => $subject,
            'title'   => $title,
            'to'      => $to_user,
            'url'     => $url,
        ]);
    }
1042154
public function show($id, $translationId)
    {
        $block = $this->getBlock($id);
        if (!empty($block)) {
            $this->authorize('read', $block);
            $translation = $this->repository->getBlockTranslationById($block, $translationId);
            if (!empty($translation)) {
                return $this->respondWithSuccess($translation, new BlockTranslationTransformer);
            }
        }
        return $this->respondNotFound();
    }
376585
public function addTranslation($translation)
    {
        $this->getTranslations()->set((string)$translation->getLocale(), $translation);
        $translation->setTranslatable($this);

        return $this;
    }
233309
public function translationsAction($language)
    {
        $language = $this->getUser()->getInterfaceLanguage($language);

        $translations = $this->get('resourcesTranslations');
        $content = $translations->get($language);

        return new Response($content, 200, ['Content-Type' => 'text/javascript']);
    }