deeplcom/deepl-php
Official PHP client for the DeepL API. Translate text and documents with simple methods like translateText(), using your DeepL authentication key. Composer install, supports PHP 7.3+ with ongoing updates as the API evolves.
translateText() in background jobs for async processing) or event listeners (e.g., translating content on eloquent.creating).TranslationService facade).DeepLClient to an interface for mocking/testing)..env).| Risk Area | Mitigation Strategy |
|---|---|
| API Rate Limits | Implement caching (e.g., Illuminate/Cache) for frequent translations. |
| Cost Management | Monitor billedCharacters and set budget alerts (e.g., via DeepL’s usage API). |
| Error Handling | Wrap calls in try-catch and log DeepL\DeepLException for observability. |
| PHP Version Support | Enforce PHP 8.1+ in composer.json to align with package requirements. |
| Dependency Bloat | Audit deeplcom/deepl-php for unused features (e.g., document translation if not needed). |
latency_optimized or quality_optimized models?Mockery or Vcr for API recording.)DeepLClient as a singleton in AppServiceProvider.Translation facade for cleaner syntax (e.g., Translation::translate($text, 'es')).TranslateRequest middleware to auto-translate routes (e.g., /en-US/*).deepl-php calls.__('welcome') with Translation::translate(__('welcome'), 'fr').translateDocument() with Laravel Storage (e.g., S3 uploads/downloads).custom_instructions for domain-specific terminology.| Component | Compatibility Notes |
|---|---|
| PHP 8.1+ | Required; use composer require php:^8.1 if upgrading. |
| Laravel 9/10 | No conflicts; leverages PSR-4 autoloading. |
| Guzzle HTTP Client | Underlying HTTP requests use Guzzle; no conflicts if not already in use. |
| Database | No direct DB access, but may store translation metadata (e.g., billedCharacters). |
| Caching | Cache responses with Illuminate/Cache (e.g., cache()->remember()). |
composer require deeplcom/deepl-php..env: DEEPL_AUTH_KEY=your_key_here.AppServiceProvider:
$this->app->singleton(DeepLClient::class, function ($app) {
return new DeepLClient(config('services.deepl.key'));
});
TranslationService facade:
public function translate(string $text, ?string $targetLang): string {
return app(DeepLClient::class)->translateText($text, null, $targetLang)->text;
}
DeepL\DeepLException.DeepLClient in PHPUnit:
$mock = Mockery::mock(DeepLClient::class);
$mock->shouldReceive('translateText')->andReturn(new TextResult('Hola'));
$this->app->instance(DeepLClient::class, $mock);
throttle middleware).spatie/fruitful) for API resilience.deeplcom/deepl-php for breaking changes (check changelog).config('services.deepl.key') for easy rotation.DeepLClient constructor.latency_optimized model). Plan for deprecation warnings in code.DEEPL_LOG=true in .env).try-catch blocks to log DeepLException details (e.g., errorCode, message).en-US vs. en-GB).$usage = app(DeepLClient::class)->getUsage();
AppServiceProvider.translateText() with arrays for bulk translations.cache()->forever()).latency_optimized for **high-volumeHow can I help you explore Laravel packages today?