Installation
composer require bsll/translation-bundle
Add the bundle to config/bundles.php:
return [
// ...
Bsll\TranslationBundle\BsllTranslationBundle::class => ['all' => true],
];
Configure Database Run migrations to create the required tables:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Import Translations Import existing translation files (e.g., YAML, XLIFF) into the database:
php bin/console bsll:translation:import --file=path/to/translations.yml --domain=messages
First Use Case
Access the GUI at /translation (or your configured route) to edit translations directly in the database.
Resources/doc/index.md for detailed setup and configuration.php bin/console list bsll to see available commands (e.g., import, export).config/routes.yaml or routing.yml:
bsll_translation:
resource: "@BsllTranslationBundle/Resources/config/routing.yaml"
Initial Setup
php bin/console bsll:translation:import --file=translations/en.yml --domain=messages
Editing Translations
/translation to view/edit translations by domain/language.Exporting Translations
php bin/console bsll:translation:export --domain=messages --output=translations/exported/
Integration with Translator
translator service with a DatabaseLoader.services.yaml includes:
Symfony\Contracts\Translation\Loader\LoaderInterface: '@bsll_translation.database_loader'
config/packages/bsll_translation.yaml:
bsll_translation:
domains:
- { name: 'validation', path: '%kernel.project_dir%/translations/validation' }
php bin/console cache:clear
Loader Override Conflict
DatabaseLoader is prioritized in services.yaml:
Symfony\Component\Translation\Loader\LoaderInterface: '@bsll_translation.database_loader'
Migration Issues
Permission Errors
/translation route. Secure it with Symfony’s security system:
# config/packages/security.yaml
access_control:
- { path: ^/translation, roles: ROLE_TRANSLATOR }
--file argument in import command).php bin/console cache:pool:clear cache.translator
Custom Fields
Translation entity (e.g., add context or priority fields) by overriding the bundle’s migrations.Custom Exporters
Bsll\TranslationBundle\Exporter\ExporterInterface and register it in services.Event Listeners
translation.updated) to trigger actions like notifications:
// src/EventListener/TranslationListener.php
public function onTranslationUpdated(TranslationEvent $event) {
// Logic here
}
Register the listener in services.yaml:
services:
App\EventListener\TranslationListener:
tags:
- { name: kernel.event_listener, event: translation.updated, method: onTranslationUpdated }
messages..env (e.g., DATABASE_URL) before running migrations.How can I help you explore Laravel packages today?