PHPackages                             jonasyeah/translator - 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. jonasyeah/translator

ActiveLibrary

jonasyeah/translator
====================

php translator for baidu, youdao

v1.0.1(6y ago)5104[2 PRs](https://github.com/jonasrepo/translator/pulls)1MITPHPPHP &gt;=5.6

Since Jul 1Pushed 3y agoCompare

[ Source](https://github.com/jonasrepo/translator)[ Packagist](https://packagist.org/packages/jonasyeah/translator)[ RSS](/packages/jonasyeah-translator/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (5)Used By (1)

Translator
==========

[](#translator)

该翻译库整合了有道和百度的翻译

特点
--

[](#特点)

- 支持有道和百度基于api的通用翻译接口
- 通过破解有道与百度翻译页面接口, 可以免注册直接使用(由于抓取的数据格式可能会被调整, 如果要在正式环境使用, 最好去服务商平台注册使用api)
- 统一调用与数据返回

环境需求
----

[](#环境需求)

- PHP &gt;= 5.6

安装
--

[](#安装)

```
$ composer require "jonasyeah/translator"
```

使用
--

[](#使用)

```
use Jonas\Translator\Translator;
use Jonas\Translator\Lng;

$config = [
	 	// HTTP 请求的超时时间（秒）, 如果不设置, 系统默认使用5秒
        'timeout' => 5.0,

        // 默认发送配置, 如果不设置, 系统默认使用有道
        'default' => [
            // 默认可用的发送网关,
            'gateways' => [
                'youdao',
            ],
        ],
        // 可用的网关配置
        //如果没有设置qpp_key 和app_sec, 系统默认使用页面抓取活的接口
        'gateways' => [
            'baidu' => [
                'app_key' => '123xxxxx',
                'app_sec' => '123xxxxx',
            ],
            'baidu' => [
				'app_key' => '123xxxxx',
				'app_sec' => '123xxxxx',
            ],
        ],
]
$translator = new Translator($config);

//使用百度翻译
$res = $translator->baidu('天气不错');
//使用有道翻译
$res = $translator->youdao('天气不错');
//可以指定被翻译成的语言
$res = $translator->to(Lng::English)->baidu('天气不错');

//使用有道和百度翻译
$res = $translator->translate('天气不错', [Translator::Youdao, Translator::Baidu]);
```

### 关于成功时返回值

[](#关于成功时返回值)

```
//使用单一翻译
$res = $translator->baidu('天气不错');
//格式
[
	'gateway' => $gateway,
	'status' => self::STATUS_SUCCESS,
	'result' => ResultInstance,
];
//使用多种翻译
[
	"baidu"	=> [
		'gateway' => 'baidu',
		'status' => self::STATUS_SUCCESS, //状态
		'result' => ResultInstance,
    ],
    "youdao"	=> [
		'gateway' => 'youdao',
		'status' => self::STATUS_SUCCESS, //状态
		'result' => ResultInstance,
    ],
]
//ResultInstance 获取结果
//翻译结果
$result->getTransResult();
//词典结果, 如果翻译的是某个词
$result->getDictResult();
//原始结果
$result->getRaw()
```

### 失败时的返回值

[](#失败时的返回值)

```
//格式
[
	'gateway' => $gateway,
	'status' => self::STATUS_FAILURE,
	'exception' => $e,
];
//如果要查看原始异常
$e->raw
```

### 异常

[](#异常)

- 网关数据异常 GatewayErrorException.php
- 网关请求异常 HttpErrorException.php
- 无效网关异常 InvalidGatewayException.php

代码贡献
----

[](#代码贡献)

由于测试及使用环境的限制，本项目中只开发了「有道」和「百度」平台的翻译。

如果您有其它支付网关的需求，或者发现本项目中需要改进的代码，***欢迎 Fork 并提交 PR！***

LICENSE
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~11 days

Total

2

Last Release

2499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1d1943702f0fecf5e120fdaa1630b6a46a66379f55673b73cb445e15f073a511?d=identicon)[jonasrepo](/maintainers/jonasrepo)

---

Top Contributors

[![jonasrepo](https://avatars.githubusercontent.com/u/22916651?v=4)](https://github.com/jonasrepo "jonasrepo (3 commits)")

### Embed Badge

![Health badge](/badges/jonasyeah-translator/health.svg)

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

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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