PHPackages                             icai/google-translate-php-one - 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. icai/google-translate-php-one

ActiveLibrary[API Development](/categories/api)

icai/google-translate-php-one
=============================

Free Google Translate API PHP Package

v5.0.0(6y ago)17MITPHPPHP ^7.1

Since Oct 17Pushed 6y agoCompare

[ Source](https://github.com/icai/google-translate-php-one)[ Packagist](https://packagist.org/packages/icai/google-translate-php-one)[ Docs](http://github.com/icai/google-translate-php-one)[ RSS](/packages/icai-google-translate-php-one/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (32)Used By (0)

Google Translate PHP
====================

[](#google-translate-php)

[![Build Status](https://camo.githubusercontent.com/86304036e7c4f0ad15fb33b6d1a3f4b99a9e42fd30506cfae7e0ccab3c983022/68747470733a2f2f7472617669732d63692e6f72672f696361692f676f6f676c652d7472616e736c6174652d7068702d6f6e652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/icai/google-translate-php-one) [![Latest Stable Version](https://camo.githubusercontent.com/e0c5f0931ea62eb5a3b5ffecb4bbd77e1e245c82572c19dbc5dc97327d482ebb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696361692f676f6f676c652d7472616e736c6174652d7068702d6f6e652e737667)](https://packagist.org/packages/icai/google-translate-php-one) [![Total Downloads](https://camo.githubusercontent.com/44a2027392ae869254dee53fa5ad647c9e6b86a5310d5536121004850fd65697/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696361692f676f6f676c652d7472616e736c6174652d7068702d6f6e652e737667)](https://packagist.org/packages/icai/google-translate-php-one) [![Downloads Month](https://camo.githubusercontent.com/9e19fadfbf5381b0635babd23eab994382f4182feb0292946f0914a955526836/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696361692f676f6f676c652d7472616e736c6174652d7068702d6f6e652e737667)](https://packagist.org/packages/icai/google-translate-php-one) [![Petreon donation](https://camo.githubusercontent.com/3566813b4190b2759b0439c2147228bec3a5a0f1ec6b7e0302305802431a7c3d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d6f72616e67652e737667)](https://www.patreon.com/stichoza) [![PayPal donation](https://camo.githubusercontent.com/b48a7f9ca978349b83c641e4901221d7e84374bcb3300a43f739835cf930e802/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d626c75652e737667)](https://paypal.me/stichoza)

Free Google Translate API PHP Package. Translates totally free of charge.

---

- **[Installation](#installation)**
- **[Basic Usage](#basic-usage)**
- [Advanced Usage](#advanced-usage)
    - [Language Detection](#language-detection)
    - [Using Raw Response](#using-raw-response)
    - [Custom URL](#custom-url)
    - [HTTP Client Configuration](#http-client-configuration)
    - [Custom Token Generator](#custom-token-generator)
    - [Errors and Exception Handling](#errors-and-exception-handling)
- [Known Limitations](#known-limitations)
- [Disclaimer](#disclaimer)
- [Donation](#donation)

Installation
------------

[](#installation)

Install this package via [Composer](https://getcomposer.org/).

```
composer require icai/google-translate-php-one

```

> Note: **PHP 7.1 or later** is required. For older versoins, use `^3.2` version of this package (see [old docs](https://github.com/icai/google-translate-php-one/tree/3.2#google-translate-php)).

Basic Usage
-----------

[](#basic-usage)

Create GoogleTranslate object

```
use Stichoza\GoogleTranslate\GoogleTranslate;

$tr = new GoogleTranslate('en'); // Translates into English
```

Or you can change languages later

```
$tr = new GoogleTranslate(); // Translates to 'en' from auto-detected language by default
$tr->setSource('en'); // Translate from English
$tr->setSource(); // Detect language automatically
$tr->setTarget('ka'); // Translate to Georgian
```

Translate sentences

```
echo $tr->translate('Hello World!');
```

Also, you can also use method chaining

```
echo $tr->setSource('en')->setTarget('ka')->translate('Goodbye');
```

Or call a shorthand static method `trans`

```
echo GoogleTranslate::trans('Hello again', 'ka', 'en');
```

Advanced Usage
--------------

[](#advanced-usage)

### Language Detection

[](#language-detection)

To detect language automatically, just set the source language to `null`:

```
$tr = new GoogleTranslate('es', null); // Or simply do not pass the second parameter
```

```
$tr->setSource(); // Another way
```

Use `getLastDetectedSource()` to get detected language:

```
$tr = new GoogleTranslate('fr');

$text = $tr->translate('Hello World!');

echo $tr->getLastDetectedSource(); // Output: en
```

Return value will be `null` if the language couldn't be detected.

Supported languages are listed in [Google API docs](https://cloud.google.com/translate/docs/languages).

### Using Raw Response

[](#using-raw-response)

For advanced usage, you might need the raw results that Google Translate provides. you can use `getResponse` method for that.

```
$responseArray = $tr->getResponse('Hello world!');
```

### Custom URL

[](#custom-url)

You can override the default Google Translate url by `setUrl` method. Useful for some countries

```
$tr->setUrl('http://translate.google.cn/translate_a/single');
```

### HTTP Client Configuration

[](#http-client-configuration)

This package uses [Guzzle](https://github.com/guzzle/guzzle) for HTTP requests. You can pass an array of [guzzle client configuration options](http://docs.guzzlephp.org/en/latest/request-options.html) as a third parameter to `GoogleTranslate` constructor, or just use `setOptions` method.

You can configure proxy, user-agent, default headers, connection timeout and so on using this options.

```
$tr = new GoogleTranslate('en', 'ka', [
    'timeout' => 10,
    'proxy' => [
        'http'  => 'tcp://localhost:8125',
        'https' => 'tcp://localhost:9124'
    ],
    'headers' => [
        'User-Agent' => 'Foo/5.0 Lorem Ipsum Browser'
    ]
]);
```

```
// Set proxy to tcp://localhost:8090
$tr->setOptions(['proxy' => 'tcp://localhost:8090'])->translate('Hello');

// Set proxy to socks5://localhost:1080
$tr->setOptions(['proxy' => 'socks5://localhost:1080'])->translate('World');
```

For more information, see [Creating a Client](http://guzzle.readthedocs.org/en/latest/quickstart.html#creating-a-client) section in Guzzle docs (6.x version).

### Custom Token Generator

[](#custom-token-generator)

You can override the token generator class by passing a generator object as a fourth parameter of constructor or just use `setTokenProvider` method.

Generator must implement `Stichoza\GoogleTranslate\Tokens\TokenProviderInterface`.

```
use Stichoza\GoogleTranslate\Tokens\TokenProviderInterface;

class MyTokenGenerator implements TokenProviderInterface
{
    public function generateToken(string $source, string $target, string $text) : string
    {
        // Your code here
    }
}
```

And use:

```
$tr->setTokenProvider(new MyTokenGenerator);
```

### Errors and Exception Handling

[](#errors-and-exception-handling)

Static method `trans()` and non-static `translate()` and `getResponse()` will throw following Exceptions:

- `ErrorException` If the HTTP request fails for some reason.
- `UnexpectedValueException` If data received from Google cannot be decoded.

In addition, `translate()` and `trans()` methods will return `null` if there is no translation available.

Known Limitations
-----------------

[](#known-limitations)

- `503 Service Unavailable` response:
    If you are getting this error, it is most likely that Google has banned your external IP address and/or [requires you to solve a CAPTCHA](https://github.com/icai/google-translate-php-one/issues/18). This is not a bug in this package. Google has become stricter, and it seems like they keep lowering the number of allowed requests per IP per a certain amount of time. Try sending less requests to stay under the radar, or change your IP frequently ([for example using proxies](#http-client-configuration)). Please note that once an IP is banned, even if it's only temporary, the ban can last from a few minutes to more than 12-24 hours, as each case is different.
- `429 Too Many Requests` response: This error is basically the same as explained above.
- `413 Request Entity Too Large` response:
    This error means that your input string is too long. Google only allows a maximum of 5000 characters to be translated at once. If you want to translate a longer text, you can split it to shorter parts, and translate them one-by-one.

Disclaimer
----------

[](#disclaimer)

This package is developed for educational purposes only. Do not depend on this package as it may break anytime as it is based on crawling the Google Translate website. Consider buying [Official Google Translate API](https://cloud.google.com/translate/) for other types of usage.

Donation
--------

[](#donation)

If this package helped you reduce your time to develop something, or it solved any major problems you had, feel free give me a cup of coffee :)

- [Patreon](https://www.patreon.com/stichoza)
- [PayPal](https://paypal.me/stichoza)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 86% 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 ~63 days

Recently: every ~83 days

Total

30

Last Release

2383d ago

Major Versions

v2.0.3 → v3.0.02015-03-18

v3.2.14 → v4.0.02018-12-03

3.2.x-dev → v5.0.02019-10-31

PHP version history (4 changes)v2.0.0PHP &gt;=5.3.29

v3.0.0PHP &gt;=5.4.0

v3.2.0PHP &gt;=5.5.0

v4.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/569a85cf1c2bddfc497d85075e4f607efda4046f4aeae03393ae11ac6b6f2617?d=identicon)[icai](/maintainers/icai)

---

Top Contributors

[![Stichoza](https://avatars.githubusercontent.com/u/1139050?v=4)](https://github.com/Stichoza "Stichoza (196 commits)")[![competitiveNN](https://avatars.githubusercontent.com/u/219689446?v=4)](https://github.com/competitiveNN "competitiveNN (5 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")[![icai](https://avatars.githubusercontent.com/u/1061012?v=4)](https://github.com/icai "icai (3 commits)")[![abenomar-uma](https://avatars.githubusercontent.com/u/52404169?v=4)](https://github.com/abenomar-uma "abenomar-uma (3 commits)")[![baijunyao](https://avatars.githubusercontent.com/u/9360694?v=4)](https://github.com/baijunyao "baijunyao (3 commits)")[![KreerC](https://avatars.githubusercontent.com/u/15277434?v=4)](https://github.com/KreerC "KreerC (2 commits)")[![consatan](https://avatars.githubusercontent.com/u/1174105?v=4)](https://github.com/consatan "consatan (2 commits)")[![gogromat](https://avatars.githubusercontent.com/u/1459688?v=4)](https://github.com/gogromat "gogromat (2 commits)")[![iflamed](https://avatars.githubusercontent.com/u/1819687?v=4)](https://github.com/iflamed "iflamed (1 commits)")[![rivajunior](https://avatars.githubusercontent.com/u/11370172?v=4)](https://github.com/rivajunior "rivajunior (1 commits)")[![rraallvv](https://avatars.githubusercontent.com/u/1840524?v=4)](https://github.com/rraallvv "rraallvv (1 commits)")[![hadjedjvincent](https://avatars.githubusercontent.com/u/3198580?v=4)](https://github.com/hadjedjvincent "hadjedjvincent (1 commits)")[![FrankDev17](https://avatars.githubusercontent.com/u/22006776?v=4)](https://github.com/FrankDev17 "FrankDev17 (1 commits)")[![subsan](https://avatars.githubusercontent.com/u/1093589?v=4)](https://github.com/subsan "subsan (1 commits)")[![tehmaestro](https://avatars.githubusercontent.com/u/9526833?v=4)](https://github.com/tehmaestro "tehmaestro (1 commits)")[![timcotten](https://avatars.githubusercontent.com/u/1017549?v=4)](https://github.com/timcotten "timcotten (1 commits)")[![ztnkv](https://avatars.githubusercontent.com/u/37043660?v=4)](https://github.com/ztnkv "ztnkv (1 commits)")

---

Tags

phptranslategoogletranslator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/icai-google-translate-php-one/health.svg)

```
[![Health](https://phpackages.com/badges/icai-google-translate-php-one/health.svg)](https://phpackages.com/packages/icai-google-translate-php-one)
```

###  Alternatives

[stichoza/google-translate-php

Free Google Translate API PHP Package

2.0k7.6M124](/packages/stichoza-google-translate-php)[statickidz/php-google-translate-free

Google Translate Free library for PHP

289258.8k6](/packages/statickidz-php-google-translate-free)[dejurin/php-google-translate-for-free

Library for free use Google Translator. With attempts connecting on failure and array support.

13943.0k2](/packages/dejurin-php-google-translate-for-free)[viniciusgava/google-translate-api

Google translate API V2 client for PHP

25391.4k5](/packages/viniciusgava-google-translate-api)[aurawindsurfing/google-translate

Free Laravel package for Paid Google Translate REST API with your own API key

1119.5k1](/packages/aurawindsurfing-google-translate)[eko/googletranslatebundle

A Symfony bundle to deals with Google Translate API

4337.1k](/packages/eko-googletranslatebundle)

PHPackages © 2026

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