Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Add 28.1: Internationalizing URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 13, 2022
1 parent a1ca415 commit 81c1637
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
default_admin_email: [email protected]
default_domain: '127.0.0.1'
default_scheme: 'http'
app.supported_locales: 'en|fr'

router.request_context.host: '%env(default:default_domain:SYMFONY_DEFAULT_ROUTE_HOST)%'
router.request_context.scheme: '%env(default:default_scheme:SYMFONY_DEFAULT_ROUTE_SCHEME)%'
Expand Down
12 changes: 9 additions & 3 deletions src/Controller/ConferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public function __construct(Environment $twig, EntityManagerInterface $entityMan
$this->bus = $bus;
}

#[Route('/', name: 'homepage')]
#[Route('/')]
public function indexNoLocale(): Response
{
return $this->redirectToRoute('homepage', ['_locale' => 'en']);
}

#[Route('/{_locale<%app.supported_locales%>}/', name: 'homepage')]
public function index(ConferenceRepository $conferenceRepository): Response
{
$response = new Response($this->twig->render('conference/index.html.twig', [
Expand All @@ -44,7 +50,7 @@ public function index(ConferenceRepository $conferenceRepository): Response
return $response;
}

#[Route('/conference_header', name: 'conference_header')]
#[Route('/{_locale<%app.supported_locales%>}/conference_header', name: 'conference_header')]
public function conferenceHeader(ConferenceRepository $conferenceRepository): Response
{
$response = new Response($this->twig->render('conference/header.html.twig', [
Expand All @@ -55,7 +61,7 @@ public function conferenceHeader(ConferenceRepository $conferenceRepository): Re
return $response;
}

#[Route('/conference/{slug}', name: 'conference')]
#[Route('/{_locale<%app.supported_locales%>}/conference/{slug}', name: 'conference')]
public function show(Request $request, Conference $conference, CommentRepository $commentRepository, NotifierInterface $notifier, string $photoDir): Response
{
$comment = new Comment();
Expand Down

0 comments on commit 81c1637

Please sign in to comment.