GithubHelp home page GithubHelp logo

waithawoo / laravel-deeplapi-translate Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 30 KB

To translate languages with Deep L Translator API

License: MIT License

PHP 100.00%
laravel deepl-translation-api deepl deepl-translate translate translate-api

laravel-deeplapi-translate's Introduction

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.

laravel-deeplapi-translate's People

Contributors

waithawoo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.