Skip to content

Commit

Permalink
04 - Add additional languages to the website
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes authored and niklasnatter committed Oct 17, 2022
1 parent 0a2c1f6 commit 4d47830
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions config/webspaces/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<localizations>
<!-- See: http://docs.sulu.io/en/latest/book/localization.html how to add new localizations -->
<localization language="en" default="true"/>
<localization language="de"/>
<localization language="fr"/>
</localizations>

<default-templates>
Expand Down Expand Up @@ -48,22 +50,22 @@
<environments>
<environment type="prod">
<urls>
<url language="en">{host}</url>
<url>{host}/{localization}</url>
</urls>
</environment>
<environment type="stage">
<urls>
<url language="en">{host}</url>
<url>{host}/{localization}</url>
</urls>
</environment>
<environment type="test">
<urls>
<url language="en">{host}</url>
<url>{host}/{localization}</url>
</urls>
</environment>
<environment type="dev">
<urls>
<url language="en">{host}</url>
<url>{host}/{localization}</url>
</urls>
</environment>
</environments>
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Website/EventWebsiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
) {
}

#[Route('/event/{id}', name: 'app.event')]
#[Route('/{_locale}/event/{id}', name: 'app.event')]
public function indexAction(int $id, Request $request): Response
{
$event = $this->eventRepository->findById($id, $request->getLocale());
Expand Down
6 changes: 6 additions & 0 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
</li>
{% endfor %}
</ul>

<div class="navbar-nav">
{% for localization in localizations %}
<a class="nav-link" href="{{ localization.url }}">{{ localization.locale }}</a>
{% endfor %}
</div>
</div>
</nav>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testIndexAction(): void
{
$event = $this->createEvent('Sulu is awesome', 'en');

$crawler = $this->client->request('GET', '/event/' . $event->getId());
$crawler = $this->client->request('GET', '/en/event/' . $event->getId());

$response = $this->client->getResponse();
$this->assertInstanceOf(Response::class, $response);
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Pages/HomepageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testHomepage(): void
],
);

$crawler = $this->client->request(Request::METHOD_GET, '/homepage');
$crawler = $this->client->request(Request::METHOD_GET, '/en/homepage');

$response = $this->client->getResponse();
$this->assertInstanceOf(Response::class, $response);
Expand Down

0 comments on commit 4d47830

Please sign in to comment.