willdurand/js-translation-bundle
Translation component) via a Symfony Bundle. Laravel’s php-symfony/translation package provides a near-identical API, enabling partial compatibility.trans() helper + manual JS exposure (e.g., via API endpoints or blade scripts) may suffice for simpler cases, but this bundle centralizes translation management and reduces duplication.php-symfony/translation package).Twig integration for template-based translation loading (Laravel’s Blade is different; workarounds needed).translations object (e.g., window.__translations__).messages, validations).ServiceProvider instead of Symfony’s Bundle; requires wrapping the bundle in a Laravel-compatible layer.mix/vite may need configuration to handle dynamic translation files.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Symfony API Mismatch | High | Use Laravel’s php-symfony/translation + adapter layer for DI/container. |
| Blade Integration | Medium | Create a custom Blade directive or middleware to inject translations. |
| Caching Complexity | Medium | Leverage Laravel’s cache (file, redis) with bundle’s cache tags. |
| JS Global Pollution | Low | Scope window.__translations__ or use a module system (e.g., ES6 imports). |
| Version Drift | Low | Monitor Symfony Translation component updates in Laravel. |
php-symfony/translation (v6+) matches the bundle’s requirements.bind() in AppServiceProvider).window.__translations__./api/translations (less coupled but more network calls).composer require php-symfony/translation willdurand/js-translation-bundle
JsTranslationServiceProvider):
use Bazinga\JsTranslationBundle\BazingaJsTranslationBundle;
use Symfony\Component\HttpKernel\KernelInterface;
class JsTranslationServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton(KernelInterface::class, function () {
return new class implements KernelInterface { /* Minimal impl */ };
});
$this->app->register(new BazingaJsTranslationBundle());
}
}
config/ structure):
php artisan vendor:publish --provider="Bazinga\JsTranslationBundle\BazingaJsTranslationBundle"
public function handle($request, Closure $next) {
$translations = app('translator')->getCatalogue()->all();
$response = $next($request);
$response->headers->set('X-Translations', json_encode($translations));
return $response;
}
// public/js/translations.js (auto-generated or manually injected)
window.__translations__ = <?php echo json_encode($translations); ?>;
const message = window.__translations__.messages.welcome;
| Component | Compatibility Notes |
|---|---|
| Laravel 10/11 | High (Symfony Translation v6+ is compatible). |
| Blade | Low (requires middleware/directive workarounds). |
| Vite/Webpack | Medium (custom loaders needed for dynamic translation files). |
| Livewire | High (translations can be preloaded or fetched via Alpine.js). |
| Inertia.js | High (translations can be included in page props). |
| React/Vue | High (global window.__translations__ works with most setups). |
php artisan cache:clear triggers).translation facade for server-side updates.translator service logs for errors.config/js_translation.php.window.__translations__ is injected (middleware/asset pipeline).php artisan cache:clear) and browser cache.Translation component logs to storage/logs/laravel.log.How can I help you explore Laravel packages today?