PHPackages                             pavelzanek/laravel-deepl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. pavelzanek/laravel-deepl

ActiveLibrary[Localization &amp; i18n](/categories/localization)

pavelzanek/laravel-deepl
========================

A Laravel package for integrating with the DeepL API.

1.0.0(1y ago)2644MITPHPPHP ^8.2

Since Aug 18Pushed 1y ago2 watchersCompare

[ Source](https://github.com/PavelZanek/laravel-deepl)[ Packagist](https://packagist.org/packages/pavelzanek/laravel-deepl)[ RSS](/packages/pavelzanek-laravel-deepl/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (8)Versions (6)Used By (0)

Laravel Deepl
=============

[](#laravel-deepl)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2f303f68a03285e668fadae3ace725f3136231da5cad350febfb6c335b7a7ec7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706176656c7a616e656b2f6c61726176656c2d646565706c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pavelzanek/laravel-deepl)[![Total Downloads](https://camo.githubusercontent.com/573858d5525ea00416ef9cb16e965b17f52cb114cb304022909c1740efe95c1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706176656c7a616e656b2f6c61726176656c2d646565706c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pavelzanek/laravel-deepl)[![GitHub Issues](https://camo.githubusercontent.com/045b05ca75a0c98b3aad7fc953bd34e2fe6462faec0f3a4e0c1b9f6b464c2898/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f506176656c5a616e656b2f6c61726176656c2d646565706c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/PavelZanek/laravel-deepl/issues)[![License](https://camo.githubusercontent.com/20adc5ffd8d9f08f9c8318e6fd26af7838304319eb63363cf7aaf6009a60411a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f506176656c5a616e656b2f6c61726176656c2d646565706c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/PavelZanek/laravel-deepl/blob/main/LICENSE.md)

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Text Translation](#text-translation)
    - [Document Translation](#document-translation)
    - [Glossary Management](#glossary-management)
    - [Language Support](#language-support)
    - [Usage Limits](#usage-limits)
- [Translating Localization Files](#translating-localization-files)
- [On-the-Fly Translation Setup](#on-the-fly-translation-setup)
- [Helpers](#helpers)
- [Additional Resources](#additional-resources)
- [Testing](#testing)
- [Linting](#linting)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)
- [Support the Developer](#support-the-developer)
- [About the Developer](#about-the-developer)

Introduction
------------

[](#introduction)

Laravel Deepl is a Laravel package that serves as a wrapper for the official [DeepL PHP client](https://github.com/DeepLcom/deepl-php), enhancing it with additional features such as caching and chainable translation methods. This package leverages the robustness of the official client while providing a more Laravel-centric interface. For comprehensive details about the DeepL API, including available endpoints and parameters, please refer to the [DeepL API Documentation](https://developers.deepl.com/docs).

Requirements
------------

[](#requirements)

Before installing and using this package, please ensure your environment meets the following minimum requirements:

- **PHP 8.2** or higher
- **Laravel 11.0** or higher
- **GuzzleHTTP 7.0** or higher

These versions are required to ensure compatibility with the package and the features it provides. Make sure your project is running on these versions or higher before integrating this package.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require pavelzanek/laravel-deepl
```

### Configuration

[](#configuration)

To publish the configuration file, run:

```
php artisan vendor:publish --tag=laravel-deepl-config
```

This will create a `config/laravel-deepl.php` file where you can set your DeepL API key and other configuration options.

### Migrations

[](#migrations)

The package includes a migration that creates the translations table used for caching translations (more info: [Text Translation](#text-translation)). To publish the migration files, run:

```
php artisan vendor:publish --tag=laravel-deepl-migrations
```

This command will copy the migration files to your application’s `database/migrations` directory.

After publishing the migrations, you need to run them to create the necessary database tables:

```
php artisan migrate
```

This will execute the migration and create the translations table in your database, enabling the caching feature.

### Environment Variables

[](#environment-variables)

Add your DeepL API key to your `.env` file:

```
DEEPL_API_KEY=your-deepl-api-key
```

Other environment variables you might want to set:

```
DEEPL_DEFAULT_SOURCE_LANG=en
DEEPL_DEFAULT_TARGET_LANG=cs
DEEPL_RETRY_ON_FAILURES=3
DEEPL_TIMEOUT=30

DEEPL_ENABLE_TRANSLATION_CACHE=true
DEEPL_TRANSLATION_CACHE_TABLE=your_custom_table_name

DEEPL_ENABLE_ON_THE_FLY_TRANSLATION=true
DEEPL_ON_THE_FLY_OUTSIDE_LOCAL=false
DEEPL_ON_THE_FLY_SOURCE_LANG=en
DEEPL_ON_THE_FLY_USE_QUEUE_FOR_TRANSLATION=true
```

Usage
-----

[](#usage)

### Usage Options: Facade vs. Client

[](#usage-options-facade-vs-client)

The package offers two primary ways to interact with the DeepL API: using the Facade or directly using the `DeeplClient` class. Additionally, the `translateText` method now supports method chaining, allowing for more flexible and readable translation requests.

**Using the Facade:**

```
use PavelZanek\LaravelDeepl\Facades\Deepl;

$translatedText = Deepl::translateText('Hello, world!', 'en', 'de');

echo $translatedText; // Outputs: Hallo, Welt!
```

**Using the DeeplClient:**

```
use PavelZanek\LaravelDeepl\DeeplClient;

$client = app(DeeplClient::class);

$translatedText = $client->translateText('Hello, world!', 'en', 'de');

echo $translatedText; // Outputs: Hallo, Welt!
```

**Note:** The result is returned as an object from the official DeepL API PHP package. For more details on the response structure, refer to the [official documentation](https://www.deepl.com/docs-api).

### Text Translation

[](#text-translation)

You can easily translate text using the provided client:

**Example Using the Facade:**

```
use PavelZanek\LaravelDeepl\Facades\Deepl;

$translatedText = Deepl::translateText('Hello, world!', 'en', 'de');

echo $translatedText; // Outputs: Hallo, Welt!
```

**Example Using the DeeplClient:**

Basic Usage Example of DeeplClient for Translating Text:

```
use PavelZanek\LaravelDeepl\DeeplClient;

$client = app(DeeplClient::class);

$translatedText = $client->translateText('Hello, world!', 'en', 'de');

echo $translatedText; // Outputs: Hallo, Welt!
```

Integrating DeeplClient into a Laravel Controller for example:

```
