Skip to content

Commit 4d47830

Browse files
wachterjohannesniklasnatter
authored andcommitted
04 - Add additional languages to the website
1 parent 0a2c1f6 commit 4d47830

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

config/webspaces/example.xml

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<localizations>
1111
<!-- See: http://docs.sulu.io/en/latest/book/localization.html how to add new localizations -->
1212
<localization language="en" default="true"/>
13+
<localization language="de"/>
14+
<localization language="fr"/>
1315
</localizations>
1416

1517
<default-templates>
@@ -48,22 +50,22 @@
4850
<environments>
4951
<environment type="prod">
5052
<urls>
51-
<url language="en">{host}</url>
53+
<url>{host}/{localization}</url>
5254
</urls>
5355
</environment>
5456
<environment type="stage">
5557
<urls>
56-
<url language="en">{host}</url>
58+
<url>{host}/{localization}</url>
5759
</urls>
5860
</environment>
5961
<environment type="test">
6062
<urls>
61-
<url language="en">{host}</url>
63+
<url>{host}/{localization}</url>
6264
</urls>
6365
</environment>
6466
<environment type="dev">
6567
<urls>
66-
<url language="en">{host}</url>
68+
<url>{host}/{localization}</url>
6769
</urls>
6870
</environment>
6971
</environments>

src/Controller/Website/EventWebsiteController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(
2121
) {
2222
}
2323

24-
#[Route('/event/{id}', name: 'app.event')]
24+
#[Route('/{_locale}/event/{id}', name: 'app.event')]
2525
public function indexAction(int $id, Request $request): Response
2626
{
2727
$event = $this->eventRepository->findById($id, $request->getLocale());

templates/base.html.twig

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
</li>
4242
{% endfor %}
4343
</ul>
44+
45+
<div class="navbar-nav">
46+
{% for localization in localizations %}
47+
<a class="nav-link" href="{{ localization.url }}">{{ localization.locale }}</a>
48+
{% endfor %}
49+
</div>
4450
</div>
4551
</nav>
4652
</div>

tests/Functional/Controller/Website/EventWebsiteControllerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testIndexAction(): void
2626
{
2727
$event = $this->createEvent('Sulu is awesome', 'en');
2828

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

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

tests/Functional/Pages/HomepageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testHomepage(): void
4747
],
4848
);
4949

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

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

0 commit comments

Comments
 (0)