GithubHelp home page GithubHelp logo

translug's Introduction

Translug

Build Status Scrutinizer Code Quality Build Status Code Coverage StyleCI Total Downloads Latest Stable Version License

来源于 translate 和 slug 这两个词的组合,目的是实现文章和帖子中文标题也可以使用 slug 类型的 url 。

Demo

CODECASTS 视频学习社区: https://www.codecasts.com/discuss ,随便点开一个问答帖子就可以看效果。

使用前必看

由于有道翻译服务全面升级:http://fanyi.youdao.com/openapi?path=data-mode

敬请使用过老版本的用户尽快升级 Translug 2.0 以上。

对应的版本说明:

Laravel Translu
5.* ~1.0
6.* or 7.* ~2.0
8.* ~3.0

安装

这是一个标准的 Composer 的包,你可以直接通过下面的命令行来安装:

composer require jellybool/translug

或者在你的 composer.json 文件中添加:

"jellybool/translug" : "~3.0"

然后执行 composer update

初始化

在 Translug 中,翻译的功能是直接使用有道翻译 API ,你首先需要在这里注册你的网站或者 App:

http://ai.youdao.com/docs/api.s

不用担心,非常简单! 有道翻译的免费接口限制为每小时最多 1000 次请求,如果需要更多 API 调用,请联系有道官方。

注册之后,需要创建一个应用,然后你会拿到两个关键的信息:

1. appKey
2. appSecret

1.Laravel 中使用

1.1 配置 默认情况在,在 laravel 项目中的 config/services.php 中添加:

  'stripe' => [
        'model' => App\User::class,
        'key' => env('STRIPE_KEY'),
        'secret' => env('STRIPE_SECRET'),
    ],
   // 下面是你添加的内容
   'youdao' => [
           'appKey' => env('YOUDAO_APP_KEY'),
           'appSecret' => env('YOUDAO_APP_SECRET'),
       ],
       
/*  如果你是从 translug:~1.0 升级的话,需要把下面的配置修改成上面的
'youdao' => [
        'key' => env('YOUDAO_API_KEY'),
        'from' => env('YOUDAO_KEY_FROM'),
    ],
 */   

当然,你还需要在 .env 文件中添加:

YOUDAO_APP_KEY=app_key
YOUDAO_APP_SECRET=app_secret

translug:~1.0 升级的话,也要对应修改这里的 .env 变量

config/app.php 中,添加 provideraliases :

 //providers
 \JellyBool\Translug\TranslugServiceProvider::class,

// aliases
'Translug' => \JellyBool\Translug\TranslugFacade::class,

1.2 使用

app('translug')->translate('如何安装 Laravel'); 
//How to install the Laravel

// or 
use Translug;
Translug::translate('如何安装 Laravel');
//How to install the Laravel

app('translug')->translug('如何安装 Laravel'); 
//how-to-install-the-laravel

// or 
use Translug;
Translug::translug('如何安装 Laravel');
//how-to-install-the-laravel

//或者你只想要 slug 的话

translug('如何安装 Laravel');
//how-to-install-the-laravel

translug('怎么理解 laravel 关联模型');
//how-to-understand-the-laravel-associated-model

//針對繁體,翻譯會有一點不一樣
translug('怎麼理解 laravel 關聯模型');
//how-to-understand-the-laravel-correlation-model

2.在普通的项目使用

2.1 设置 appKey 和 appSecret

use JellyBool\Translug\Translug;

$translug = new Translug(['appKey' => 'your_key_from', 'appSerect' => 'your_api_key' ]);
// 或者也可以这样
$translug = new Translug();
$translug->setConfig('appKey' => 'your_key_from', 'appSerect' => 'your_api_key']);

2.2 使用

$translug->translate('如何安装 Laravel');
//How to install the Laravel

$translug->translug('如何安装 Laravel');
//how-to-install-the-laravel

translug's People

Contributors

jellybool avatar summerblue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

translug's Issues

Laravel 6 Support

Jelly

image

Laravel 6 版本,可能需要适配下,虽然可以通过 重写安装 helper 来实现

composer require laravel/helpers

ide-helper 包安装时提示的错误

运行 php artisan ide-helper:generate

提示的错误

Type error: Argument 2 passed to JellyBool\Translug\Translation::__construct() must be of the type array, null given, called in /Users/my-fc/Code/atf-yyz/vendor/jellybool/translug/src/TranslugServiceProvider.php on line 35  

有道api已更改,我更改之后,appKey无法读取env

private function getTranslateUrl($text)
{
    $args = [
        'q' => $text,
        'from' => "zh-CHS",
        'to' => "EN",
        'appKey' => $this->config['appKey'],
        'salt' => rand(10000,99999),
    ];

    $args['sign'] = md5($this->config['appKey'] . $text . $args['salt'] . $this->config['appSecret']);
    $ret = $this->api.http_build_query($args);

    return $ret;
}

这是我更改的内容,请帮忙指点

RequestExceptioncURL error 60: SSL certificate problem:

(1/1) RequestExceptioncURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

in CurlFactory.php (line 187)
at CurlFactory::createRejection(object(EasyHandle), array('errno' => 60, 'error' => 'SSL certificate problem: unable to get local issuer certificate', 'url' => 'https://openapi.youdao.com/api?from=zh-CHS&to=EN&sign=4d0db5c10d8a618f72dc761ffe1c29d3&appKey=***&salt=f95c4b9205ed5f2e34dbd73fd0db5886&q=%E5%A6%82%E4%BD%95%E5%AE%89%E8%A3%85+Laravel', 'content_type' => null, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 1, 'redirect_count' => 0, 'total_time' => 0.094, 'namelookup_time' => 0.016, 'connect_time' => 0.047, 'pretransfer_time' => 0.0, 'size_upload' => 0.0, 'size_download' => 0.0, 'speed_download' => 0.0, 'speed_upload' => 0.0, 'download_content_length' => -1.0, 'upload_content_length' => -1.0, 'starttransfer_time' => 0.0, 'redirect_time' => 0.0, 'redirect_url' => '', 'primary_ip' => '220.181.76.82', 'certinfo' => array(), 'primary_port' => 443, 'local_ip' => '192.168.3.111', 'local_port' => 58532))in CurlFactory.php (line 150)
at CurlFactory::finishError(object(CurlHandler), object(EasyHandle), object(CurlFactory))in CurlFactory.php (line 103)
at CurlFactory::finish(object(CurlHandler), object(EasyHandle), object(CurlFactory))in CurlHandler.php (line 43)

安装了JellyBool/translug,在控制器中使用此包时,报错

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.