Skip to content

datashaman/laravel-translators

Repository files navigation

laravel-translators

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel manager for translators. WIP.

Includes drivers for:

Installation

The OpenAI driver is the default, which can be changed easily.

You must still install the package with the driver you want to use:

composer require datashaman/laravel-translators openai-php/client // for OpenAI
composer require datashaman/laravel-translators google/cloud-translate // for Google Translate
composer require datashaman/laravel-translators deeplcom/deepl-php // for DeepL Translator

The Azure AI Translator driver uses the REST API, so no additional packages are required:

composer require datashaman/laravel-translators

You can publish the config file if you wish to customize it in some way:

php artisan vendor:publish --tag="laravel-translators-config"

This is not necessary if you are using the default configuration.

Usage

use Datashaman\LaravelTranslators\Facades\Translator;

// Default is OpenAI
$translations = Translator::translate(['Hello, world!'], 'fr'); // ["Bonjour, monde !"]

$translations = Translator::driver('azure')->translate(['Hello, World!'], 'fr'); // ["Salut tout le monde!"]

$translations = Translator::driver('deepl')->translate(['Hello, World!'], 'fr'); // ["Bonjour à tous !"]

$translations = Translator::driver('google-v2')->translate(['Hello, World!'], 'fr'); // ["Bonjour le monde!"]

$translations = Translator::driver('google-v3')->translate(['Hello, World!'], 'fr'); // ["Bonjour le monde!"]

The default driver is OpenAI. You can change the default driver (set TRANSLATOR_DRIVER in your .env file).

There are various configuration requirements per service to setup before they can be used. There is an example .env file with all the configuration options. You are also free to modify the config and environment variables (once config is published) to suit your own schema.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages