devture/symfony-translation-bundle
Installation
composer require --dev devture/symfony-translation-bundle
Add to config/bundles.php:
Devture\Bundle\TranslationBundle\DevtureTranslationBundle::class => ['dev' => true],
Configure in config/packages/devture_translation.yaml
devture_translation:
base_dirs: ['%kernel.project_dir%/translations']
source_locale: 'en'
locales: ['en', 'fr', 'es']
domains: ['messages', 'another-domain']
First Use Case
/_translation route in your browser (default path).messages.en.json → messages.fr.json).Translation File Structure
Organize translations in translations/ (or custom base_dirs):
translations/
├── messages.en.json
├── messages.fr.json
├── another-domain.en.json
└── another-domain.fr.json
Domain-Specific Workflows
domains config to scope translations (e.g., messages, validation).validation.en.json) from UI messages.Hash Files for Sync
Leverage .hash.json files to detect outdated translations:
{ "key": "source_hash" }
Symfony Integration
translator service:
$this->get('translator')->trans('key', [], 'messages');
cache:clear or cache:warmup.CI/CD Pipelines
php bin/console devture:translation:validate
File Permissions
www-data) can write to translations/:
chmod -R 775 translations/
Locale Mismatches
source_locale matches your .json files (e.g., messages.en.json).locales config to avoid UI errors.Hash File Conflicts
.hash.json files if translations appear "untranslated" unexpectedly:
rm translations/*.hash.json
Domain-Specific Issues
twig) from domains config.php bin/console debug:config devture_translation
php bin/console debug:router | grep translation
Default route: /_translation.Custom Templates
Override Twig templates in templates/devture_translation/:
templates/
└── devture_translation/
├── base.html.twig
└── translation.html.twig
Authentication
Secure the /_translation route via firewall:
# config/packages/security.yaml
access_control:
- { path: ^/_translation, roles: ROLE_TRANSLATOR }
Event Listeners Extend functionality via events (e.g., post-save hooks):
// src/EventListener/TranslationListener.php
public function onTranslationSave(TranslationEvent $event) {
// Custom logic (e.g., notify Slack)
}
Translation Validation Add custom validation rules:
devture_translation:
validation_rules:
messages: ['required', 'min_length:1']
How can I help you explore Laravel packages today?