Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

04 - Add additional languages to the website #9

Open
wants to merge 1 commit into
base: assignment/03
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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