SuperSeller3000/migrations/Version20260520010000.php
Simon Kuehn ec159d7b3a feat: DB-backed translations editable in admin
- 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>
2026-05-18 07:53:52 +00:00

53 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Yaml\Yaml;
final class Version20260520010000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Seed translation files (admin domain, en + de) into app.translations';
}
public function up(Schema $schema): void
{
// intentionally empty — data inserted in postUp
}
public function postUp(Schema $schema): void
{
$translationsDir = dirname(__DIR__).'/translations';
foreach (['en', 'de'] as $locale) {
$file = $translationsDir."/admin.{$locale}.yaml";
if (!file_exists($file)) {
continue;
}
$data = Yaml::parseFile($file);
if (!\is_array($data)) {
continue;
}
foreach ($data as $key => $value) {
$this->connection->executeStatement(
'INSERT INTO app.translations (id, locale, domain, translation_key, value)
VALUES (gen_random_uuid(), ?, ?, ?, ?)
ON CONFLICT (locale, domain, translation_key) DO NOTHING',
[$locale, 'admin', (string) $key, (string) $value]
);
}
}
}
public function down(Schema $schema): void
{
$this->addSql("DELETE FROM app.translations WHERE domain = 'admin'");
}
}