- How do I install deeplcom/deepl-php in a Laravel project?
- Run `composer require deeplcom/deepl-php` in your project root. The package requires PHP 7.3+ (recommended: 8.1+). No additional Laravel-specific setup is needed beyond initializing the `DeepLClient` with your API key.
- Can I use this package for real-time translations in a Laravel Livewire app?
- Yes. Initialize the `DeepLClient` in your Livewire component and call `translateText()` directly. For performance, cache frequent translations using Laravel’s cache system or queue async jobs for heavy workloads.
- What Laravel versions does deeplcom/deepl-php support?
- The package works with Laravel 9/10+ and PHP 7.3+. For new projects, use PHP 8.1+ to align with DeepL’s recommended version. No Laravel-specific dependencies exist, so it’s framework-agnostic.
- How do I handle API rate limits or cost management in production?
- Monitor `billedCharacters` in responses and set budget alerts via DeepL’s usage API. Cache translations with `Illuminate/Cache` for repeated requests. For batch processing, use Laravel queues to avoid hitting rate limits.
- Can I translate documents (PDFs, DOCX) with this package?
- Yes. Use the `translateDocument()` method, which supports file uploads. For Laravel, pair it with Laravel Storage (e.g., S3) to handle file uploads/downloads. Async processing via Laravel Jobs is recommended for large files.
- How do I mock DeepL responses for unit testing?
- Use Mockery to stub the `DeepLClient` or record API responses with VCR (e.g., `vcr/vcr`). For Laravel, bind the client to an interface in the service container to swap implementations during tests.
- Is there a way to integrate this with Laravel Scout for translated search?
- Yes. Translate content before indexing with Scout by calling `translateText()` in your `toSearchableArray()` method. Store translations in a separate column or use Laravel’s attribute casting for dynamic translations.
- How do I securely store my DeepL API key in Laravel?
- Never hardcode keys. Use Laravel’s `.env` file (e.g., `DEEPL_API_KEY`) and access it via `config('services.deepl.key')`. Restrict file permissions and use environment variables in CI/CD pipelines.
- What’s the best way to structure translations in a Laravel app?
- Create a `TranslationService` facade wrapping `DeepLClient` for cleaner syntax (e.g., `Translation::translate($text, 'es')`). For dynamic content, use Laravel’s `eloquent.creating` event to auto-translate fields.
- Are there alternatives to deeplcom/deepl-php for Laravel?
- Other PHP DeepL clients exist (e.g., unofficial wrappers), but this is the **official** library with full API feature support and active maintenance. For Laravel, consider Google Translate’s API (`google/cloud-translate`) if DeepL’s pricing is prohibitive.