PHPackages                             gongziyan/translate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gongziyan/translate

ActiveLibrary

gongziyan/translate
===================

集成百度翻译，有道翻译，谷歌翻译

081PHP

Since Apr 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/JianJiaPHP/translate)[ Packagist](https://packagist.org/packages/gongziyan/translate)[ RSS](/packages/gongziyan-translate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Translate for PHP
=================

[](#translate-for-php)

---

Installing
----------

[](#installing)

```
$ composer require GongZiYan/translate
```

### configuration

[](#configuration)

```
// config/translate.php

return [
    // 使用什么翻译驱动
    // 目前支持: "baidu", "youdao", "google"
    /**
     *  默认使用google  google使用的是免费接口爬取，目前能用，为了确保稳定，请配置一个备用服务， 目前只有google和baidu 支持繁体翻译
     **/

    'defaults' => [
        'driver' => 'google',   // 默认使用google翻译
        'spare_driver' => 'baidu',  // 备用翻译api ,第一个翻译失败情况下，调用备用翻译服务，填写备用翻译api 需要在下面对应的drivers中配置你参数
        'from' => 'zh',   // 原文本语言类型 ，目前支持：auto【自动检测】,en【英语】,zh【中文】,hk【繁体】，jp【日语】,ko【韩语】，fr【法语】，ru【俄文】，pt【西班牙】
        'to' => 'en',     // 翻译文本 ：en【英语】,zh【中文】,hk【繁体】，jp【日语】,ko【韩语】，fr【法语】，ru【俄文】，pt【西班牙】,
    ],

    'drivers' => [
        'baidu' => [
            'base_url' => 'https://api.fanyi.baidu.com/api/trans/vip/translate',
            'app_id' => '',
            'app_key' => '',
        ],

        'youdao' => [
            'base_url' => 'https://openapi.youdao.com/api',
            'app_id' => '',
            'app_key' => '',
        ],

        'google' => [
            'base_url' => 'http://translate.google.cn/translate_a/single',
            'app_id' => '',
            'app_key' => '',
        ],
    ],
];
```

Usage
-----

[](#usage)

```
use GongZiYan\Translate\TranslateService;

$config = include($youerpath.'/translate.php');

$obj = new TranslateService($config);
$result = $obj->translate('你知道我对你不仅仅是喜欢');
print_r($result);
```

Example:

```
 // 动态更改翻译服务商
 $config = include($youerpath.'/translate.php');
 $obj = new TranslateService($config);
 $obj->driver('baidu')->translate('你知道我对你不仅仅是喜欢');
 print_r($result);
 //You know I'm not just like you

 // 动态更改语种

 $from = 'en';
 $to = 'zh';
 $result =  $obj->driver('baidu')->from($from)->to($to)->translate('I love you.');
print_r($result);
```

License
-------

[](#license)

MIT

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba3cd91f8e0ebb0c0ce5f3d3699ab00b8b991a209db940d245967e9ba6cf7ba2?d=identicon)[JianJiaPHP](/maintainers/JianJiaPHP)

---

Top Contributors

[![Snow0101518](https://avatars.githubusercontent.com/u/203526531?v=4)](https://github.com/Snow0101518 "Snow0101518 (5 commits)")[![JianJiaPHP](https://avatars.githubusercontent.com/u/43328671?v=4)](https://github.com/JianJiaPHP "JianJiaPHP (2 commits)")

### Embed Badge

![Health badge](/badges/gongziyan-translate/health.svg)

```
[![Health](https://phpackages.com/badges/gongziyan-translate/health.svg)](https://phpackages.com/packages/gongziyan-translate)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
