lexik/translation-bundle
Symfony bundle to manage translations in a database: import from xliff/yml/php, edit via a web GUI, track missing domain translations, add new keys, and export back to files. Database loader overrides file-based translations.
.yml, .xliff, .php) with a Doctrine entity model (LexikTranslationBundle\Entity\Translation), enabling dynamic updates, versioning (via Doctrine events), and querying (e.g., "find untranslated strings").DatabaseLoader for Laravel’s container).trans() helper) can be extended to use this bundle’s DatabaseLoader as a fallback. Example:
// config/app.php
'translator' => [
'loader' => [
'lexik' => [
'class' => Lexik\TranslationBundle\Loader\DatabaseLoader::class,
'order' => 100, // Load after file-based loaders
],
],
],
Translation, TranslationDomain) can be mapped directly. For Eloquent, a custom adapter would be needed to bridge Doctrine entities to Eloquent models..yml, .xliff, and .php files. Laravel projects using these formats can migrate existing translations with minimal effort.lexik:translation:import) require Laravel command adaptation or a custom facade.config('app.cache_translations'))?spatie/laravel-translation-loader, laravel-localization) or third-party APIs (e.g., Crowdin, Lokalise)?| Laravel Component | Lexik Bundle Compatibility | Integration Strategy |
|---|---|---|
| Translation System | Supports trans() helper via DatabaseLoader fallback. |
Extend Laravel’s translator to use the bundle’s loader. Override AppServiceProvider. |
| Doctrine ORM | Native support if using Laravel Doctrine. | Map bundle entities to Doctrine models. Use existing migrations. |
| Eloquent ORM | No native support. | Create a custom adapter to sync Doctrine entities with Eloquent models. |
| Console/Artisan | Symfony commands (e.g., lexik:translation:import) cannot be used directly. |
Rewrite commands as Laravel Artisan commands or use a facade to call Symfony services. |
| Twig | Admin GUI uses Twig. | Replace with Blade templates or use Inertia/Livewire for a modern frontend. |
| Symfony Components | Requires Symfony’s DI, Console, and Form components. | Use Laravel Symfony Bridge or isolate bundle dependencies (e.g., via Composer). |
| File Storage | Imports/exports .yml, .xliff, .php. |
Leverage Laravel’s filesystem (storage_path()) for translation file storage. |
| Caching | No built-in Laravel cache integration. | Extend DatabaseLoader to use Laravel’s cache (e.g., Cache::remember). |
Assessment Phase:
resources/lang).validation, auth) and map them to the bundle’s TranslationDomain entity.Setup Phase:
composer require lexik/translation-bundle
// config/lexik_translation.php
return [
'loader' => [
'database' => [
'class' => Lexik\TranslationBundle\Loader\DatabaseLoader::class,
'order' => 100, // Load after file-based loaders
],
],
'gui' => [
'enabled' => env('LEXIK_TRANSLATION_GUI', false), // Disable if using CLI-only
],
];
php artisan doctrine:mapping:import App\Entity --path=vendor/lexik/translation-bundle/Resources/config/doctrine
php artisan doctrine:schema:update --force
Data Migration:
php artisan lexik:translation:import --format=yml --dir=resources/lang
(Note: Requires adapting the Symfony command to Laravel.)use Lexik\TranslationBundle\Entity\Translation;
use Lexik\TranslationBundle\Entity\TranslationDomain;
Translation::create([
'domain' => TranslationDomain::findOrCreate('messages'),
'locale' => 'en',
'message' => 'welcome',
'translation' => 'Welcome!',
]);
Translation System Override:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->
How can I help you explore Laravel packages today?