- Add Translation entity (locale/domain/key/value, unique on all three) - Add TranslationRepositoryInterface + DoctrineTranslationRepository - Add DatabaseTranslator decorator (#[AsDecorator]) that checks DB first and falls back to YAML files; clears per-request cache on setLocale() - Add TranslationCrudController with locale/domain filters and read-only key/locale/domain on edit to prevent accidental renames - Add "Übersetzungen / Translations" menu entry in DashboardController - Migration 20260520000000: create app.translations table - Migration 20260520010000: seed from admin.en.yaml + admin.de.yaml (204 rows) - Flatten admin.de.yaml to dot-notation; add new keys for translation CRUD Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Infrastructure\Persistence\Repository;
|
|
|
|
use App\Domain\I18n\Repository\TranslationRepositoryInterface;
|
|
use App\Domain\I18n\Translation;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
final class DoctrineTranslationRepository implements TranslationRepositoryInterface
|
|
{
|
|
public function __construct(private readonly EntityManagerInterface $em) {}
|
|
|
|
public function findMapByLocaleAndDomain(string $locale, string $domain): array
|
|
{
|
|
$rows = $this->em->createQuery(
|
|
'SELECT t.key, t.value FROM App\Domain\I18n\Translation t
|
|
WHERE t.locale = :locale AND t.domain = :domain'
|
|
)
|
|
->setParameter('locale', $locale)
|
|
->setParameter('domain', $domain)
|
|
->getArrayResult();
|
|
|
|
$map = [];
|
|
foreach ($rows as $row) {
|
|
$map[$row['key']] = $row['value'];
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
public function findAll(): array
|
|
{
|
|
return $this->em->createQuery(
|
|
'SELECT t FROM App\Domain\I18n\Translation t ORDER BY t.domain ASC, t.locale ASC, t.key ASC'
|
|
)->getResult();
|
|
}
|
|
|
|
public function save(Translation $translation): void
|
|
{
|
|
$this->em->persist($translation);
|
|
$this->em->flush();
|
|
}
|
|
|
|
public function remove(Translation $translation): void
|
|
{
|
|
$this->em->remove($translation);
|
|
$this->em->flush();
|
|
}
|
|
}
|