survos / babel-bundle
Lightweight translation base (Str/StrTranslation) + Translatable attribute & subscriber
Fund package maintenance!
Requires
- php: ^8.5
- ext-intl: *
- ext-mbstring: *
- doctrine/doctrine-bundle: ^2.7|^3.0
- doctrine/orm: ^3.7
- doctrine/persistence: ^4.1
- survos/lingua-contracts: ^2.5
- survos/lingua-core: ^2.5
- symfony/console: ^7.4||^8.1
- symfony/dependency-injection: ^7.4||^8.1
- symfony/http-kernel: ^7.4||^8.1
- symfony/property-access: ^7.4||^8.1
- symfony/translation: ^7.4||^8.1
Requires (Dev)
- nette/php-generator: ^4.1
- nikic/php-parser: ^5.6
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^13.0
- survos/translator-bundle: ^2.5
- symfony/phpunit-bridge: ^7.4||^8.1
- thomas-0816/doctrine-dbal-duckdb: ^1.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- 2.45.23
- 2.45.21
- 2.45.20
- 2.41.9
- 2.39.0
- 2.34.29
- 2.33.0
- 2.24.30
- 2.18.20
- 2.14.1
- 2.12.10
- 2.12.9
- 2.10.19
- 2.10.18
- 2.10.17
- 2.10.16
- 2.10.15
- 2.10.14
- 2.10.13
- 2.10.12
- 2.10.11
- 2.10.10
- 2.10.9
- 2.10.8
- 2.10.7
- 2.10.6
- 2.10.5
- 2.10.4
- 2.10.3
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.4
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.23
- 2.7.22
- 2.7.21
- 2.7.20
- 2.7.19
- 2.7.18
- 2.7.17
- 2.7.16
- 2.7.15
- 2.7.14
- 2.7.13
- 2.7.12
- 2.7.11
- 2.7.10
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.0.220
- 2.0.219
- 2.0.218
- 2.0.217
- 2.0.216
- 2.0.215
- 2.0.214
- 2.0.213
- 2.0.212
- 2.0.211
- 2.0.210
- 2.0.209
- 2.0.208
- 2.0.207
- 2.0.206
- 2.0.205
- 2.0.204
- 2.0.203
- 2.0.202
- 2.0.201
- 2.0.200
- 2.0.199
- 2.0.198
- 2.0.197
- 2.0.196
- 2.0.195
- 2.0.194
- 2.0.193
- 2.0.192
- 2.0.191
- 2.0.190
- 2.0.189
- 2.0.188
- 2.0.187
- 2.0.186
- 2.0.185
- 2.0.184
- 2.0.183
- 2.0.182
- 2.0.181
- 2.0.180
- 2.0.179
- 2.0.178
- 2.0.177
- 2.0.176
- 2.0.175
- 2.0.174
- 2.0.173
- 2.0.172
- 2.0.171
- 2.0.170
- 2.0.169
- 2.0.168
- 2.0.167
- 2.0.166
- 2.0.165
- 2.0.164
- 2.0.163
- 2.0.162
- 2.0.161
- 2.0.160
- 2.0.159
- 2.0.158
- 2.0.156
- 2.0.155
- 2.0.154
- 2.0.146
- 2.0.145
- 2.0.144
- 2.0.143
- 2.0.142
- 2.0.141
- 2.0.140
- 2.0.139
- 2.0.138
- 2.0.136
- 2.0.135
- 2.0.134
- 2.0.133
- 2.0.132
- 2.0.131
- 2.0.130
- 2.0.129
- 2.0.128
- 2.0.127
- 2.0.126
- 2.0.125
- 2.0.124
- 2.0.123
- 2.0.122
- 2.0.121
- 2.0.120
- 2.0.119
- 2.0.117
- 2.0.116
- 2.0.115
- 2.0.114
- 2.0.113
- 2.0.112
- 2.0.111
- 2.0.110
- 2.0.109
- 2.0.108
- 2.0.107
- 2.0.106
- 2.0.105
- 2.0.104
- 2.0.103
- 2.0.102
- 2.0.101
- 2.0.100
- 2.0.99
- 2.0.98
- 2.0.97
- 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-11-03 02:37:30 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\Contract\BabelHooksInterface; use Survos\BabelBundle\Entity\Traits\BabelHooksTrait; use Survos\Lingua\Contracts\Attribute\Translatable; #[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.
Locale-aware Doctrine Instant Search
When both Babel and SearchBundle's searchFieldPredicate hook are installed,
Babel automatically supplies matching predicates for string-backed translatable
fields in Doctrine searches. Configure either o.label or o.labelBacking in
DoctrineAdapter::SEARCH_FIELDS; Babel uses its compiled TranslatableIndex.
No application-specific joins or translation generation are needed.
Matching follows the display locale: nonblank target translations are searched; source text is searched when that locale is the source language or when the translation is missing. Empty provider stubs never hide populated translations. If multiple providers have nonblank text, the highest translation row ID wins consistently in both hydration and search. Ordinary identifiers remain searchable.
The integration uses DQL source-set subqueries, so translation rows cannot multiply hits, totals or facet counts. The same predicate runs before pagination and facet self-exclusion. Source-language matching skips translation tables. Semantic search continues to use its vector candidates, without applying literal keyword matching. SQLite and DuckDB are covered by the same ORM regression tests.
The searched entity manager must map Babel's Str and StrTranslation entities.
Source locales can be fixed in Babel metadata, use the application default, or
come from a mapped property containing normalized locale codes. A computed method
accessor needs an explicit searchable locale property. Other search adapters and
installations without a compatible SearchBundle remain unchanged.