PHPackages                             carlin/laravel-translate-drives - 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. [API Development](/categories/api)
4. /
5. carlin/laravel-translate-drives

ActiveLibrary[API Development](/categories/api)

carlin/laravel-translate-drives
===============================

Baidu, Alibaba Cloud Translate, and Google Translate driver package, ready to use out of the box

v1.0.0(1y ago)113↓100%Apache-2.0PHP

Since Jul 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/carlin-rj/laravel-translate-drives)[ Packagist](https://packagist.org/packages/carlin/laravel-translate-drives)[ RSS](/packages/carlin-laravel-translate-drives/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Baidu, Alibaba Cloud Translate, and Google Translate driver package, ready to use out of the box
------------------------------------------------------------------------------------------------

[](#baidu-alibaba-cloud-translate-and-google-translate-driver-package-ready-to-use-out-of-the-box)

[**简体中文 🇨🇳**](README_cn.md)

### Translate driver package usage tutorial

[](#translate-driver-package-usage-tutorial)

#### Environmental requirements

[](#environmental-requirements)

- `PHP` &gt;= 8.0

install
-------

[](#install)

```
composer require carlin/laravel-translate-drives

```

publish config
--------------

[](#publish-config)

```
php artisan vendor:publish --provider="Carlin\LaravelTranslateDrives\TranslateDrivesServiceProvider"
```

Usage
-----

[](#usage)

### Baidu

[](#baidu)

```
use Carlin\LaravelTranslateDrives\Facades\TranslateManager;

$query = '我喜欢你的冷态度 :test';
$res = TranslateManager::baidu()->translate($query, LangCode::EN);
$res->getDst(); //translate text
$res->getSrc(); //origin text
$res->getOriginal(); //original result

//Custom configuration
$res = TranslateManager::baidu(['app_id'=>'', 'app_key'=>''])->translate($query, LangCode::EN);
```

### Google

[](#google)

```
use Carlin\LaravelTranslateDrives\Facades\TranslateManager;

$query = '我喜欢你的冷态度 :test';
$res = TranslateManager::google()->translate($query, LangCode::EN);
```

### Alibaba cloud

[](#alibaba-cloud)

```
use Carlin\LaravelTranslateDrives\Facades\TranslateManager;

$query = '我喜欢你的冷态度 :test';
$res = TranslateManager::alibabaCloud()->translate($query, LangCode::EN);

//Custom configuration
$res = TranslateManager::alibabaCloud(['app_id'=>'', 'app_key'=>''])->translate($query, LangCode::EN);
```

Custom driver
-------------

[](#custom-driver)

```
use Carlin\TranslateDrives\Providers\AbstractProvider;
use Carlin\LaravelTranslateDrives\Facades\TranslateManager;
class MyTranslateDriver extends AbstractProvider
{
    public function __construct(?string $app_id = null, ?string $app_key = null, array $config = [])
    {
        parent::__construct($app_id, $app_key, $config);

        //you code
    }

    protected function handlerTranslate(string $query, string $to = LangCode::EN, string $from = LangCode::AUTO): Translate
    {
        //you translation code
        return new Translate([
            'src'=>'',
            'dst'=>'',
        ]);
    }
    protected function mapTranslateResult(array $translateResult): array
    {
        //you translate Result code
        return [

        ];
    }
}

$query = '我喜欢你的冷态度 :test';
$res = TranslateManager::extend('my_driver', function ($allConfig) {
    $config = $allConfig['drives']['my_driver'] ?? [];
    //you configuration code
    return new MyTranslateDriver(config:$config);
})->driver('my_driver')->translate($query);
```

Preserving Parameters
---------------------

[](#preserving-parameters)

The `preserveParameters()` method allows you to preserve certain parameters in strings while performing translations. This is particularly useful when dealing with localization files or templating engines where specific placeholders need to be excluded from translation.

Default regex is `/:(\w+)/` which covers parameters starting with :. Useful for translating language files of Laravel and other frameworks. You can also pass your custom regex to modify the parameter syntax.

```
use Carlin\LaravelTranslateDrives\Facades\TranslateManager;
use Carlin\TranslateDrives\Supports\Provider;
use Carlin\TranslateDrives\Supports\LangCode;

$query = '我喜欢你的冷态度 :test';
$res = TranslateManager::google()->preserveParameters()->translate($query, LangCode::EN); //I like your cold attitude :test
```

Or use custom regex:

```
use Carlin\LaravelTranslateDrives\Facades\TranslateManager;
use Carlin\TranslateDrives\Supports\Provider;
use Carlin\TranslateDrives\Supports\LangCode;

$query = '我喜欢你的冷态度 {{test}}';
$res = TranslateManager::google()->preserveParameters('/\{\{([^}]+)\}\}/')->translate($query, LangCode::EN); //I like your cold attitude :test
```

If you have a better translation driver, please feel free to submit a PR
------------------------------------------------------------------------

[](#if-you-have-a-better-translation-driver-please-feel-free-to-submit-a-pr)

###  Health Score

24

—

LowBetter than 35% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

612d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/545110c66db1405c084c9e1de3e2f4e12b4857b4ebf06b8074c3510a150fb826?d=identicon)[mckue](/maintainers/mckue)

---

Top Contributors

[![carlin-rj](https://avatars.githubusercontent.com/u/140769537?v=4)](https://github.com/carlin-rj "carlin-rj (8 commits)")

---

Tags

phplaraveltranslatedrivergoogle-translateAlibaba cloudfree-google-translatebaidutranslate drives

### Embed Badge

![Health badge](/badges/carlin-laravel-translate-drives/health.svg)

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

###  Alternatives

[yxx/laravel-quick

agile development

145.1k](/packages/yxx-laravel-quick)

PHPackages © 2026

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