Skip to content

waithawoo/laravel-deeplapi-translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel DeepL API Translation Package

GitHub issues GitHub stars GitHub forks GitHub license

To translate languages with Deep L Translator API

Easy to use Deep L API for translation in Laravel projects

Installation

Install this package via Composer.

composer require waithaw/deeplapitranslate

You can publish the config file using the following command:

php artisan vendor:publish --provider="WaiThaw\DeeplTranslate\DeeplTranslateServiceProvider"

This will create the package's config file called deepltranslate.php in the config directory. The contents of the published config file are as follows.

return [
    /*
      |-------------------------------------------------------------------------------
      | Api Key generated from Deep L account.
      |-------------------------------------------------------------------------------
      */
    'auth_key' => env('DEEPL_TRANSLATE_API_KEY'),

    /*
      |-------------------------------------------------------------------------------
      | Api Endpoint URL from Deep L account.
      |-------------------------------------------------------------------------------
      */
    'api_url' => env('DEEPL_TRANSLATE_API_ENDPOINT_URL'),
];

Usage

  • After setting up the config file values in .env, you can use translation methods.

Create DeeplTranslate object

use WaiThaw\DeeplTranslate\DeeplTranslate;

$deepl = new DeeplTranslate();

Translate

// parameters are $text, $source_language, $target_language
$translated_text = $deepl->translate('are you hungry?', 'EN', 'JA'); // Output translated text string

echo $translated_text;

Supported languages

$languages = $deepl->languages();
foreach($languages as $lang){
    echo $lang['language']."-".$lang['name'].'<br>';
}

For supported Source-languages

$source_languages = $deepl->languages('source');
foreach($source_languages as $lang){
    echo $lang['language']."-".$lang['name'].'<br>';
}

For supported Target-languages

$target_languages = $deepl->languages('target');
foreach($target_languages as $lang){
    echo $lang['language']."-".$lang['name'].'<br>';
}

Monitoring Usage

You can monitor the number of traslated characters and maximun limitations

$usage= $deepl->usage();
echo $usage['character_count'].' characters have been used. Maximum number of characters that can be translated in the current billing period are '.$usage['character_limit'];

Setting for cURL timeout

You can setup a timeout to prevent waiting in case of api unreachable

$deepl->setTimeout(10);

Security

If you discover any security related issues, please email them to [email protected] instead of using the issue tracker.

License

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