定制 picolab/translator 二次开发

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

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

picolab/translator

Composer 安装命令:

composer require picolab/translator

包简介

Simple translating class with translation providers

README 文档

README

Simple translator class with some translate providers

Usage

 $translator = new Picolab\Translator\Translator();
 
 // set up your translating provider from available providers
 $translator->setProvider($translateProvider);
 
 // translate:
 $translation = $translator->from('en')->to('ru')->translate('Some other language');
 
 // You can output the results immediately with echo
 echo $translation;
 // output:
 // Другой язык
 
 $outputResponse = $translation->getResponse();
 //output: 
 /*
 Array
 (
     [code] => 200
     [to] => ru
     [from] => en
     [text] => Array
         (
             [0] => Другой язык
         )
 
 )
 */

// You can use language autodetect feature, if provider is supporting it:
$translation = $translator->to('ru')->translate('Some other language');
// output $translation->getResponse():
/*
  Array
  (
      [code] => 200
      [to] => ru
      [from] => en
      [text] => Array
          (
              [0] => Другой язык
          ) 
  )
  */
 
 // You can even use arrays for translating multiple texts
 $translation = $translator->to('ru')->translate(['Some other language', 'Some other value']);
 // $translation->getResponse():
 /*
   Array
   (
       [code] => 200
       [to] => ru
       [from] => en
       [text] => Array
           (
               [0] => Другой язык
               [1] => другое значение
           )   
   )
   */
// p.s. in this case  echo $translation  will output only first array item   

Providers use Guzzle Http client, if you have specific guzzle client configuration, you can set up with setGuzzleInstance function

 $translator = new Picolab\Translator\Translator();
 
 $translator->setGuzzleInstance($yourGuzzleClientInstance);
 ...
 

Available providers

Microsoft Translator service provider

dev docs: https://msdn.microsoft.com/en-us/library/dd576287.aspx

 $translateProvider = new Picolab\Translator\Providers\BingProvider([
     'client_id' => 'client id',
     'client_secret' => 'client secret',
 ]);
    

Yandex provider

dev docs: https://translate.yandex.com/developers

$translateProvider = new Picolab\Translator\Providers\YandexProvider([
     'key' => 'your api key',
 ]);

Tilde Machine Translation provider

dev docs: http://www.tilde.com/mt/tools/api

Due to the fact that available languages is already defined in the MT system, you do not need to specify them there, but provider class will output system source and target language

$translateProvider = new Picolab\Translator\Providers\LetsMTProvider([
    'client_id' => 'client ID',
    'systemID' => 'System ID',
 ]);
 
$translator = new Picolab\Translator\Translator();
$translator->setProvider($translateProvider);

// Due to the fact that available languages is already defined in the MT system, 
// you do not need to specify them there
// Translation system EN-LV
$translation = $translator->translate('Some other language');
// output first translation 
echo $translation;

Google Translate API provider

dev docs: https://cloud.google.com/translate/docs/

$translateProvider = new Picolab\Translator\Providers\GoogleProvider([
    'api_key' => 'your api key'
]);
 

License: MIT

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固