survos / babel-bundle
Lightweight translation base (Str/StrTranslation) + Translatable attribute & subscriber
Fund package maintenance!
kbond
Installs: 519
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/survos/babel-bundle
Requires
- php: ^8.4
- ext-intl: *
- ext-mbstring: *
- doctrine/doctrine-bundle: ^2.7|^3.0
- doctrine/orm: ^2.12 || ^3.3
- doctrine/persistence: ^4.1
- survos/lingua-contracts: ^2.0
- survos/lingua-core: ^2.0
- symfony/console: ^7.3||^8.0
- symfony/dependency-injection: ^7.3||^8.0
- symfony/http-kernel: ^7.3||^8.0
- symfony/property-access: ^7.3||^8.0
- symfony/translation: ^7.3||^8.0
Requires (Dev)
- nette/php-generator: ^4.1
- nikic/php-parser: ^5.6
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12
- roave/security-advisories: dev-latest
- survos/translator-bundle: ^2.0
- symfony/phpunit-bridge: ^8.0
- 2.0.96
- 2.0.95
- 2.0.94
- 2.0.93
- 2.0.92
- 2.0.91
- 2.0.90
- 2.0.89
- 2.0.88
- 2.0.87
- 2.0.86
- 2.0.85
- 2.0.84
- 2.0.83
- 2.0.82
- 2.0.81
- 2.0.80
- 2.0.79
- 2.0.78
- 2.0.77
- 2.0.76
- 2.0.75
- 2.0.74
- 2.0.73
- 2.0.72
- 2.0.71
- 2.0.70
- 2.0.69
- 2.0.68
- 2.0.67
- 2.0.66
- 2.0.65
- 2.0.64
- 2.0.63
- 2.0.62
- 2.0.61
- 2.0.60
- 2.0.59
- 2.0.58
- 2.0.57
- 2.0.56
- 2.0.55
- 2.0.54
- 2.0.53
- 2.0.51
- 2.0.50
- 2.0.49
- 2.0.48
- 2.0.47
- 2.0.46
- 2.0.45
- 2.0.44
- 2.0.43
- 2.0.42
- 2.0.41
- 2.0.40
- 2.0.39
- 2.0.38
- 2.0.37
- 2.0.36
- 2.0.35
- 2.0.34
- 2.0.33
- 2.0.32
- 2.0.31
- 2.0.30
- 2.0.29
- 2.0.28
- 2.0.27
- 2.0.26
- 2.0.25
- 2.0.24
- 2.0.23
- 2.0.22
- 2.0.21
- 2.0.20
- 2.0.19
- 2.0.18
- 2.0.17
- 2.0.16
- 2.0.15
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- dev-main / 1.x-dev
- dev-babel-locale
This package is auto-updated.
Last update: 2026-01-05 18:04:11 UTC
README
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.
Core idea (read this first)
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.
Hard requirements (non-negotiable)
If you violate any of these, Babel will not work.
1. PHP 8.4 property hooks
This bundle requires PHP 8.4.
2. BabelHooksInterface must be implemented
Entities using Babel must implement:
Survos\BabelBundle\Contract\BabelHooksInterface
The easiest way is to use the provided trait:
use Survos\BabelBundle\Entity\Traits\BabelHooksTrait;
⚠️ The compiler pass relies on this interface. If it is missing, the entity will not be indexed.
3. Naming convention is strict
For every logical field foo:
| Purpose | Name |
|---|---|
| Backing property | fooBacking |
| Runtime property | foo |
The compiler pass and runtime resolver assume this naming.
Minimal working example
<?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; } }
Database model (important)
Babel stores translations outside your entities.
Source strings (str)
One row per unique source string + locale.
Translations (str_translation)
One row per (source, targetLocale) pair.
Your entities never store translations directly.
Commands (opinionated subset)
Only these commands are considered current and supported:
babel:debug babel:carriers babel:scan babel:stats babel:str babel:tr
Everything else should be treated as experimental or legacy.
See doc/commands.md for details.
⚠️ Known broken / legacy areas (read before using)
babel:translate
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).
Code generation
All previous code generators for Babel have been removed.
They caused more confusion than value.
Documentation now reflects manual, explicit setup only.
Documentation
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
Philosophy
Babel is intentionally:
- explicit over magical
- inspectable over clever
- boring at runtime
- powerful at scale
Once wired correctly, it disappears into the background.