-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add internationalization for error messages and static pages
The changes include internationalization for error messages and static pages URL. New Symfony translation files for error pages and time validation have been added. The language is now automatically set from the HTTP Accept-Language header. ItemController includes a new function 'addItem' to handle item creation.
- Loading branch information
Showing
20 changed files
with
757 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
# Symfony + PWA = 💕 | ||
|
||
## Introduction | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
framework: | ||
default_locale: en | ||
set_locale_from_accept_language: true | ||
set_content_language_from_locale: true | ||
enabled_locales: '%app.supported_locales%' | ||
default_locale: '%app.default_locale%' | ||
translator: | ||
default_path: '%kernel.project_dir%/translations' | ||
fallbacks: | ||
- en | ||
providers: | ||
- en_US | ||
providers: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Form\ItemHandler; | ||
use App\Repository\ItemRepository; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
class ItemController extends AbstractController | ||
{ | ||
public function __construct( | ||
private readonly ItemHandler $itemHandler, | ||
private readonly ItemRepository $itemRepository, | ||
){} | ||
|
||
#[Route('/add', name: 'app_add_item', methods: [Request::METHOD_POST])] | ||
public function addItem(Request $request): Response | ||
{ | ||
$form = $this->itemHandler->prepare(); | ||
$item = $this->itemHandler->handle($form, $request); | ||
if ($item !== null) { | ||
$this->addFlash('success', 'Item added'); | ||
return $this->redirectToRoute('app_homepage'); | ||
} | ||
$this->addFlash('error', 'Item not added'); | ||
return $this->redirectToRoute('app_homepage'); | ||
} | ||
|
||
#[Route('/items/{id}/toggle', name: 'app_toggle', methods: [Request::METHOD_POST])] | ||
public function toggle(string $id): Response | ||
{ | ||
$item = $this->itemRepository->findOneById($id); | ||
if ($item !== null) { | ||
$item->toggle(); | ||
$this->itemRepository->save($item); | ||
} | ||
$this->addFlash('success', 'Item state changed'); | ||
|
||
return $this->redirectToRoute('app_homepage'); | ||
} | ||
|
||
#[Route('/items/{id}/remove', name: 'app_remove', methods: [Request::METHOD_POST])] | ||
public function remove(string $id): Response | ||
{ | ||
$item = $this->itemRepository->findOneById($id); | ||
if ($item !== null) { | ||
$this->itemRepository->remove($item); | ||
} | ||
$this->addFlash('success', 'Item removed'); | ||
|
||
return $this->redirectToRoute('app_homepage'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
final class RootController extends AbstractController | ||
{ | ||
public function __construct( | ||
#[Autowire(param: 'app.default_locale')] | ||
private readonly string $defaultLocale, | ||
#[Autowire(param: 'app.supported_locales')] | ||
private readonly array $supportedLocales, | ||
) { | ||
} | ||
|
||
#[Route('/', name: 'app_root', methods: [Request::METHOD_GET])] | ||
public function __invoke(Request $request): Response | ||
{ | ||
$locale = | ||
$request->attributes->get('_locale') ?? | ||
$request->getSession() | ||
->get('_locale') ?? | ||
$request->getPreferredLanguage($this->supportedLocales) ?? | ||
$this->defaultLocale | ||
; | ||
|
||
return $this->redirectToRoute('app_homepage', [ | ||
'_locale' => $locale, | ||
], Response::HTTP_SEE_OTHER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\PreloadGenerator; | ||
|
||
use SpomkyLabs\PwaBundle\CachingStrategy\PreloadUrlsGeneratorInterface; | ||
use SpomkyLabs\PwaBundle\Dto\Url; | ||
use SpomkyLabs\PwaBundle\Dto\Manifest; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
final readonly class StaticPagesUrlPreloadGenerator implements PreloadUrlsGeneratorInterface | ||
{ | ||
public function __construct( | ||
#[Autowire('%kernel.enabled_locales%')] | ||
private array $locales, | ||
){} | ||
|
||
public function getAlias(): string | ||
{ | ||
return 'static_pages'; | ||
} | ||
|
||
/** | ||
* @return iterable<Url|string> | ||
*/ | ||
public function generateUrls(): iterable | ||
{ | ||
foreach ($this->locales as $locale) { | ||
yield Url::create( | ||
'app_homepage', | ||
[ | ||
'_locale' => $locale, | ||
] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.