How to add a custom translatable model?
Making the custom model translatable
Step 1: Create the Translation Entity
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Model\AbstractTranslation;
use Sylius\Component\Resource\Model\TranslationInterface;
use Sylius\Resource\Model\ResourceInterface;
#[ORM\Entity]
#[ORM\Table(name: 'app_supplier_translation')]
class SupplierTranslation extends AbstractTranslation implements ResourceInterface, TranslationInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255)]
private ?string $description = null;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): void
{
$this->name = $name;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
}Step 2: Update the Supplier Entity to Use Translations
Step 3: Create Form Types:
SupplierType (Main Form Type)
SupplierTranslationType (Translation Subform)
Register the Form Types
Step 4: Update Your Routing and Resource Configuration
Register the Resource and Translation
Define Admin Routes
Configure grid
Configure Translations
Step 5: Update the Database with Migrations
Generate the Migration
Run the Migration
🎯 Pimp Your Translations Section Using Twig Hooks and a Dedicated Macro
🧩 1: Use the Built-In Macro to Render Translations
🧱 2: Create Hookable Twig Templates
📝 3: Define Individual Translation Fields
🔧 4: Configure the twig hooks:
✅ 5: Final Result: Translations Section in the Admin Panel

Last updated
Was this helpful?
