Installation
composer require disjfa/translation-bundle
Add to config/bundles.php (Symfony) or config/app.php (Laravel via bridge):
Disjfa\TranslationBundle\DisjfaTranslationBundle::class => ['all' => true],
Database Setup
Run migrations (check src/Resources/migrations/ for schema):
php artisan migrate # If using Laravel bridge
# OR
php bin/console doctrine:migrations:migrate # Symfony
First Use Case
config/packages/disjfa_translation.yaml (Symfony) or .env (Laravel):
disjfa_translation:
enabled: true
table_name: translation_entries
$this->get('translator')->trans('your.key');
// Dynamic updates will persist to DB on save.
Translation Overrides
translation_entries table.$translator = $this->get('translator');
$translator->setLocale('en');
$translator->trans('welcome.message', ['%name%' => 'John']);
// Save override to DB (triggered by UI action).
Layered Translation Loading
translations/ or YAML/JSON files).Integration with Forms
// Symfony Form Type
$builder->add('translation_key', TextType::class, [
'attr' => ['data-translation-bundle' => true],
]);
Caching Strategy
framework.translation.cache_warmer = false) to ensure real-time DB updates.Cache::forget('translations');
Cache Invalidation
php bin/console cache:clear
Locale-Specific Overrides
setLocale() is called before edits.locale column to the translation_entries table if granularity is needed.Migration Conflicts
table_name in config or extend the migration class.Performance
translation_entries(key, locale) and limit queries with WHERE locale = ?.translation.logger to track unresolved keys:
framework:
translation:
logging: true
translation_entries:
SELECT * FROM translation_entries WHERE key = 'your.key';
Custom Storage
Disjfa\TranslationBundle\Storage\TranslationStorageInterface to support Redis or API-backed overrides.Event Listeners
disjfa_translation.pre_save to validate or transform translations before DB storage.UI Integration
data-translation-bundle attribute to auto-link form fields to translation keys (requires JS):
$('[data-translation-bundle]').on('change', function() {
const key = $(this).data('key'); // Implement key extraction logic
// Send to backend via AJAX.
});
Fallback Logic
Disjfa\TranslationBundle\Loader\TranslationLoader to add fallback locales dynamically:
public function load($locale, $domain = null) {
$translations = parent::load($locale, $domain);
if (empty($translations)) {
$translations = $this->load('en', $domain); // Fallback to English
}
return $translations;
}
How can I help you explore Laravel packages today?