<commit_before><?php

namespace Opifer\CmsBundle\Controller\Frontend;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class ExceptionController extends Controller
{
    /**
     * 404 error page.
     *
     * @return Response
     */
    public function error404Action()
    {
        $contentRepository = $this->getDoctrine()->getRepository('OpiferCmsBundle:Content');
        $content = $contentRepository->findOneBySlug('404');
        if ($content) {
            return $this->forward('OpiferContentBundle:Frontend/Content:view', [
                'content' => $content,
                'statusCode' => 404,
            ]);
        }

        $response = new Response();
        $response->setStatusCode(404);

        return $this->render('OpiferCmsBundle:Exception:error404.html.twig', [], $response);
    }
}
<commit_msg>Render 404 page from correct locale (#359)<commit_after><?php

namespace Opifer\CmsBundle\Controller\Frontend;

use Opifer\CmsBundle\Entity\Locale;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ExceptionController extends Controller
{
    /**
     * 404 error page.
     * 
     * @param Request $request
     * @return Response
     */
    public function error404Action(Request $request)
    {

        $slugParts = explode('/', $request->getPathInfo());
        $locale = $this->getDoctrine()->getRepository(Locale::class)
            ->findOneByLocale($slugParts[1]);

        $contentRepository = $this->getDoctrine()->getRepository('OpiferCmsBundle:Content');

        if (!$locale || !$content = $contentRepository->findOneBySlug($locale->getLocale().'/404')) {
            $content = $contentRepository->findOneBySlug('404');
        }

        if ($content) {
            return $this->forward('OpiferContentBundle:Frontend/Content:view', [
                'content' => $content,
                'statusCode' => 404,
            ]);
        }

        $response = new Response();
        $response->setStatusCode(404);

        return $this->render('OpiferCmsBundle:Exception:error404.html.twig', [], $response);
    }
}

{'fraction_non_alphanumeric': 0.13856502242152466, 'fraction_numerical': 0.02062780269058296, 'mean_word_length': 2.92091388400703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2557581', 'n_tokens_mistral': 652, 'n_tokens_neox': 609, 'n_words': 100}