- Can I use this bundle in Laravel 10+ without Symfony components?
- Yes, but you’ll need to bridge Symfony dependencies like `symfony/cache` and `symfony/event-dispatcher` with Laravel’s equivalents. Use polyfills (e.g., `symfony/http-foundation` for Laravel 10) or replace them with native Laravel services. The core translation logic remains compatible.
- How do I import translations from existing Laravel lang/ files into the database?
- The bundle provides CLI commands like `translation:import` for CSV/JSON/DB sync. For Laravel’s `lang/` files, write a custom importer script using `File::all()` to parse JSON/YAML files, then bulk-insert them via Eloquent or Doctrine. Fallback chains (e.g., `en` → `es`) must be manually configured in the DB.
- Will this bundle work with Eloquent instead of Doctrine ORM?
- Officially, it requires Doctrine, but you can adapt it for Eloquent by creating a custom repository or using `laravel-doctrine/orm` to bridge the two. The translation entities (e.g., `Translation`) can be mapped to Eloquent models with minor adjustments to query builders and relationships.
- Is the admin GUI mandatory, or can I manage translations via API?
- The GUI is optional and uses Symfony UX/Twig. For Laravel, replace it with Blade templates or a headless API (e.g., `/api/translations`). Use Laravel’s built-in API resources or Livewire/Inertia for a SPA-friendly interface. The bundle’s core translation logic works without the GUI.
- How do I handle missing translations—fallback to lang/ files or show defaults?
- Configure fallback logic in your `AppServiceProvider` by extending Laravel’s `Translator` facade. The bundle supports DB-stored translations first, then falls back to `lang/` files or default values. Use middleware to check the DB before hitting the filesystem, or override the `get()` method in a custom translator.
- What’s the best caching strategy for 10K+ translations in production?
- Use Redis or APCu via Laravel’s cache system (`config/translation.php`). Cache translation groups (e.g., `messages`, `validation`) separately to reduce DB load. For high traffic, implement a two-tier cache: Redis for hot translations and DB for fallbacks. Clear cache on updates via `translation:clear-cache` CLI command.
- Can I restrict the admin GUI to specific users (e.g., Sanctum/SPA auth)?
- Yes, the GUI can be secured with Laravel’s auth systems. Use middleware like `auth:sanctum` or `auth:api` to gate routes. For SPAs, integrate with Sanctum or Passport. The bundle’s permissions are managed via Symfony’s security component, which may need adaptation for Laravel’s auth contracts.
- Are there alternatives to this bundle that are more Laravel-native?
- For Eloquent-only solutions, consider `spatie/laravel-translatable` (simpler, no GUI) or `mcamara/laravel-localization` (route-based). For externalized translations, use Crowdin or Lokalise APIs. This bundle stands out for its DB storage + GUI combo, but it trades Laravel-native simplicity for Symfony’s flexibility.
- How do I configure the bundle to work with Laravel’s existing translation middleware?
- The bundle integrates with Laravel’s `App::setLocale()` and `trans()` helpers out of the box. Extend the `TranslationMiddleware` to check the DB before falling back to `lang/` files. Ensure your `config/app.php` includes the bundle’s service provider and merge its config with Laravel’s `translation.php`.
- What’s the migration path if I switch from lang/ files to DB storage later?
- Start by duplicating your `lang/` files into the DB using the import CLI. Gradually replace `trans()` calls with the bundle’s `Translation` model queries. Use feature flags or environment checks to toggle between storage methods during migration. Test fallback chains thoroughly to avoid broken translations.