SurvosBabelBundle provides normalized translation storage with runtime locale resolution using PHP 8.4 property hooks.
This bundle is intentionally opinionated and not plug-and-play. It is designed for:
- applications with many translatable entities,
- batch translation workflows,
- search indexing per locale,
- avoiding per-entity translation join tables.
If you want “EntityTranslation tables per entity”, this is not that bundle.
Every translatable field has two representations:
- A persisted backing field (the source text)
- A runtime property hook (the localized value)
Example:
$product->title = 'Chair'; // write source text
echo $product->title; // read localized text (if available)Only the backing field is persisted. The localized value is resolved at runtime.
If you violate any of these, Babel will not work.
This bundle requires PHP 8.4.
Entities using Babel must implement:
Survos\BabelBundle\Contract\BabelHooksInterfaceThe easiest way is to use the provided trait:
use Survos\BabelBundle\Entity\Traits\BabelHooksTrait;For every logical field foo:
| Purpose | Name |
|---|---|
| Backing property | fooBacking |
| Runtime property | foo |
The compiler pass and runtime resolver assume this naming.
<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Survos\BabelBundle\Attribute\BabelStorage;
use Survos\BabelBundle\Attribute\Translatable;
use Survos\BabelBundle\Contract\BabelHooksInterface;
use Survos\BabelBundle\Entity\Traits\BabelHooksTrait;
#[ORM\Entity]
#[BabelStorage] // Property-hook storage mode
class Product implements BabelHooksInterface
{
use BabelHooksTrait;
#[ORM\Id, ORM\GeneratedValue, ORM\Column]
public ?int $id = null;
#[ORM\Column(nullable: true)]
public ?string $titleBacking = null;
#[Translatable]
public ?string $title {
get => $this->resolveTranslatable('title', $this->titleBacking);
set => $this->titleBacking = $value;
}
}Babel stores translations outside your entities.
One row per unique source string + locale.
One row per (source, targetLocale) pair.
Your entities never store translations directly.
Only these commands are considered current and supported:
babel:debug
babel:carriers
babel:scan
babel:stats
babel:str
babel:trEverything else should be treated as experimental or legacy.
See doc/commands.md for details.
babel:translate currently references obsolete field names
(hash, original, locale, etc.).
It does not match the current entities:
StrBase:code,sourceLocale,source,context,metaStrTranslationBase:strCode,targetLocale,engine,text,status
Until this is refactored, do not rely on babel:translate.
Use the event system instead (see docs).
All previous code generators for Babel have been removed.
They caused more confusion than value.
Documentation now reflects manual, explicit setup only.
doc/concepts.md— mental model & invariantsdoc/setup.md— manual setup onlydoc/commands.md— what still mattersdoc/examples.md— Product + event listenerdoc/troubleshooting.md— common failures
Babel is intentionally:
- explicit over magical
- inspectable over clever
- boring at runtime
- powerful at scale
Once wired correctly, it disappears into the background.