定制 waithaw/deeplapitranslate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

waithaw/deeplapitranslate

Composer 安装命令:

composer require waithaw/deeplapitranslate

包简介

To translate languages with Deep L Translator API in Laravel

README 文档

README

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 waithawoocw@gmail.com instead of using the issue tracker.

License

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

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固