PHPackages                             hstanleycrow/easyphptranslate - 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. hstanleycrow/easyphptranslate

ActiveLibrary[API Development](/categories/api)

hstanleycrow/easyphptranslate
=============================

PHP class to use Google Translate API

001PHP

Since May 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hstanleycrow/EasyPHPGoogleTranslate)[ Packagist](https://packagist.org/packages/hstanleycrow/easyphptranslate)[ RSS](/packages/hstanleycrow-easyphptranslate/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

EasyPHPGoogleTranslate
======================

[](#easyphpgoogletranslate)

Easy Google translate API V2 client for PHP

English Instructions
--------------------

[](#english-instructions)

This project abstract the google translate api version 2.0 in PHP. This is a easy way to implement and use the Google API Translations into PHP and his spirit is to keep it simple and easy to use.

How to install
--------------

[](#how-to-install)

```
# Clone this repository
$ git clone https://github.com/hstanleycrow/EasyPHPGoogleTranslate

# install libraries
$ composer update
```

or

```
# Install using composer
$ composer require hstanleycrow/easyphptranslate
```

Examples of usage
-----------------

[](#examples-of-usage)

This examples are using [DotEnv](https://github.com/vlucas/phpdotenv) to configure the APIKey, but you can setup it as you wwant.

### Example 1: simple translation.

[](#example-1-simple-translation)

Use this code to translate from one language to another.

```
$myPrivateApiKey = $_ENV['GOOGLE_API_KEY'];

$textToTranslate = "Hola Mundo";
$sourceLanguage = Null;
$targetLanguage = "fr";
$translateObj = new EasyPHPTranslate($myPrivateApiKey, (new CurlRequest(EasyPHPTranslate::ENDPOINT)));
$translatedText = $translateObj->translate($textToTranslate, $targetLanguage);
$originalTextWordCount = $translateObj->wordCount($textToTranslate);
$translatedTextWordCount = $translateObj->wordCount($translatedText);

echo "";
echo "Text to translate: $textToTranslate" . PHP_EOL;
echo "Word count: $originalTextWordCount" . PHP_EOL;
echo "Translated Text: $translatedText" . PHP_EOL;
echo "Translated Word count: $translatedTextWordCount" . PHP_EOL;
echo "";
```

### Example 2: Multiple language translations

[](#example-2-multiple-language-translations)

With this code, you can translate a text to a final language, passing before for other languagees. This can change a little bit the translations, simulating a re-phrase, it is very simple but useful.

```
$textToTranslate = "Hola Mundo, espero que estes bien";
$sourceLanguage = Null;
$targetLanguages = ["fr", "pt", "nl", "en"];
$translateObj = new EasyPHPTranslate($myPrivateApiKey, new CurlRequest(EasyPHPTranslate::ENDPOINT));

$translatedText = $translateObj->multipleTranslate($textToTranslate, $targetLanguages);
echo "";
echo "Text to translate: $textToTranslate" . PHP_EOL;
echo "Final Translated Text: $translatedText" . PHP_EOL;
echo "";
```

List of supported languages
---------------------------

[](#list-of-supported-languages)

This class try to be simple, so, the detection for a valid language is out of their scope, but maybe later. [List of languages](https://cloud.google.com/translate/docs/languages) supported for Google Translation API V2.

PHP Versions
------------

[](#php-versions)

I have tested this class only in this PHP versions. So, if you have an older version and do not work, let me know.

PHP VersionPHP 8.0PHP 8.1PHP 8.2Instrucciones en Español
========================

[](#instrucciones-en-español)

Este proyecto abstraee la API de traducción de Google V2.0 en PHP. Es una forma muy sencilla de usare la API de Google para traducir textos con PHP y su espiritu es mantenerlo simple y fácil de usar, sin configuraciones complejas ni nada por el estilo.

Como instalar
-------------

[](#como-instalar)

```
# Clonar repositorio
$ git clone https://github.com/hstanleycrow/EasyPHPGoogleTranslate
```

or

```
# Instalar usando composer
$ composer require hstanleycrow/easyphptranslate
```

Ejemplos de uso
---------------

[](#ejemplos-de-uso)

Estos ejemplos usan [DotEnv](https://github.com/vlucas/phpdotenv) para configurar la API Key, pero tu puedes configurarla como te plazca.

### Ejemplo 1: traducción simple con autodetección de idioma

[](#ejemplo-1-traducción-simple-con-autodetección-de-idioma)

Usa este ejemplo para traducir un texto. Solo debes definir el lenguaje al que quieres traducir, el idioma origen lo detecta la API.

```
$myPrivateApiKey = $_ENV['GOOGLE_API_KEY'];

$textToTranslate = "Hola Mundo";
$sourceLanguage = Null;
$targetLanguage = "fr";
$translateObj = new EasyPHPTranslate($myPrivateApiKey, new CurlRequest(EasyPHPTranslate::ENDPOINT));

$translatedText = $translateObj->translate($textToTranslate, $targetLanguage);
$originalTextWordCount = $translateObj->wordCount($textToTranslate);
$translatedTextWordCount = $translateObj->wordCount($translatedText);

echo "";
echo "Text to translate: $textToTranslate" . PHP_EOL;
echo "Word count: $originalTextWordCount" . PHP_EOL;
echo "Translated Text: $translatedText" . PHP_EOL;
echo "Translated Word count: $translatedTextWordCount" . PHP_EOL;
echo "";
```

### Ejemplo 2: Traducción multiple.

[](#ejemplo-2-traducción-multiple)

Con este código puedes traducir un texto a un lenguaje final pero pasando por otros lenguajes primero. De esta forma se puede cambiar un poco el resultadod de la traducción, especialmente en textos largos, simulando asi un parafraseado, simple claro pero usable.

```
$textToTranslate = "Hola Mundo, espero que estes bien";
$sourceLanguage = Null;
$targetLanguages = ["fr", "pt", "nl", "en"];
$translateObj = new EasyPHPTranslate($myPrivateApiKey, new CurlRequest(EasyPHPTranslate::ENDPOINT));

$translatedText = $translateObj->multipleTranslate($textToTranslate, $targetLanguages);
echo "";
echo "Text to translate: $textToTranslate" . PHP_EOL;
echo "Final Translated Text: $translatedText" . PHP_EOL;
echo "";
```

Lista de lenguajes soportados
-----------------------------

[](#lista-de-lenguajes-soportados)

Esta clase intenta ser simple, por eso la validación del lenguaje esta fuera de su alcance, pero tal vez luego lo incorpore junto a otras funcionalidades. [Lista de lenguajes](https://cloud.google.com/translate/docs/languages) soportados por la API de traducción de Google V2.

Versiones de PHP
----------------

[](#versiones-de-php)

He probado esta clase en estas versiones de PHP, asi qaue si tienes una version anterior y no funciona, dejame saberlo para mejorar el código.

PHP VersionPHP 8.0PHP 8.1PHP 8.2Support
-------

[](#support)

[![Buy Me A Coffee](https://camo.githubusercontent.com/b32d80c4bde7464703f7dcbb8dd24902a7b2de6b0f52a872563f87293d4eb87a/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f707572706c655f696d672e706e67)](https://www.buymeacoffee.com/haroldcrow)

License
-------

[](#license)

MIT

---

> [www.hablemosdeseo.net](https://www.hablemosdeseo.net) · GitHub [@hstanleycrow](https://github.com/hstanleycrow) · Twitter [@harold\_crow](https://twitter.com/harold_crow)

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity23

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/713da77764977a76a357f6b34361a7ab51bd55ea847b84112e3a38f5496af173?d=identicon)[hstanleycrow](/maintainers/hstanleycrow)

---

Top Contributors

[![hstanleycrow](https://avatars.githubusercontent.com/u/7930763?v=4)](https://github.com/hstanleycrow "hstanleycrow (17 commits)")

### Embed Badge

![Health badge](/badges/hstanleycrow-easyphptranslate/health.svg)

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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