darkcat/twig-translation-bundle
en.example.com, fr.example.com), where the same codebase serves different languages via distinct domains. This aligns with monolithic Symfony/Laravel apps with language isolation (not dynamic language switching per request).{{ 'text'|trans }}). Replaces dynamic trans filters with pre-translated plain text in cached templates, reducing runtime overhead.trans() helpers) differ significantly. Direct porting is not feasible without a wrapper layer (e.g., custom Blade directive or Twig bridge).trans logic) and TwigBundle (for template caching).php-gettext or laravel-translation-manager would need adaptation to replicate Symfony’s translation extension behavior.trans filter. A custom Blade directive (e.g., @translate) would need to mirror the bundle’s logic.RequestContext for locale. Laravel’s route middleware or session-based locale would need synchronization.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Twig Dependency | High | Requires Twig integration (e.g., via tightenco/ziggy or php-twig) or a custom Blade wrapper. |
| Translation Logic | Medium | Laravel’s trans() uses MessageFormatter; Symfony’s TranslationExtension differs. May need a shim class to unify behavior. |
| Caching Invalidation | High | Twig cache invalidation is tied to Symfony’s event system. Laravel’s cache tags or manual invalidation would be needed. |
| Multi-Language Routing | Medium | Assumes domain-based routing. Laravel’s locale middleware or subdomain routing (e.g., spatie/laravel-route-attributes) must align. |
| Performance Gains | Low | Unproven in Laravel; requires benchmarking against native trans() caching. |
en.app.com), or is dynamic language switching (e.g., user preference) required?TranslationComponent.php artisan view:clear)? Will the bundle’s pre-translation logic conflict?trans()) adapt to pre-translated templates?@translate) that replicates the bundle’s logic.TranslationExtension with Laravel’s Translator interface).Phase 1: Proof of Concept
tightenco/ziggy for routing + Twig).symfony/ux-twig-component).trans() in Blade.Phase 2: Blade Integration
@translate) that:
{{ trans('key') }} with pre-translated strings during cache generation.trans() under the hood but stores translated output in a temporary cache.// In a service provider:
Blade::directive('translate', function ($key) {
return "<?php echo e(__('{$key}')); ?>";
});
@translate('Strange Things') // Outputs plain text in cache
Phase 3: Language Routing
fr.app.com).public function handle($request, Closure $next) {
$locale = $request->getHost() === 'fr.app.com' ? 'fr' : 'en';
app()->setLocale($locale);
return $next($request);
}
Phase 4: Cache Optimization
php artisan view:clear.file, redis) to avoid runtime lookups.| Component | Compatibility Notes |
|---|---|
| Laravel 10.x | High (Blade directives, service container). |
| Symfony Components | Medium (TranslationComponent can be polyfilled via symfony/translation). |
| Twig | Low (unless using a bridge like tightenco/ziggy). |
| Translation Backends | High (works with JSON, gettext, or DB-driven translations). |
| Caching Drivers | High (supports file, redis, memcached). |
view:clear).php artisan view:clear + cache rebuild).view:clear.public function test_pre_translated_cache() {
$this->artisan('view:clear');
$response = $this->get('/page');
$this->assertStringContainsString('Bonjour', $response->content());
}
view:clear (may slow deployments).How can I help you explore Laravel packages today?