PHPackages                             samsonphp/google\_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. [Utility &amp; Helpers](/categories/utility)
4. /
5. samsonphp/google\_translate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

samsonphp/google\_translate
===========================

Google Translate SamsonPHP module

1.0.1(11y ago)3521Open Software License (OSL) v 3.0PHP

Since Jan 22Pushed 11y ago2 watchersCompare

[ Source](https://github.com/SamsonPHP/google_translate)[ Packagist](https://packagist.org/packages/samsonphp/google_translate)[ RSS](/packages/samsonphp-google-translate/feed)WikiDiscussions master Synced today

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

SamsonPHP Google Translate API module
=====================================

[](#samsonphp-google-translate-api-module)

[![Latest Stable Version](https://camo.githubusercontent.com/21e79f3a4eab5b28004d23f824cf6648884795865ded940db0e6146bc7b93e27/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e7068702f676f6f676c655f7472616e736c6174652f762f737461626c652e737667)](https://packagist.org/packages/samsonphp/google_translate)[![Build Status](https://camo.githubusercontent.com/e0939dbe39846686cb023e2ecd79852ca28dfd384fbfd4ab7f3c8e2160e72df1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d736f6e7068702f676f6f676c655f7472616e736c6174652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samsonphp/google_translate/badges/build.png?b=master)[![Code Coverage](https://camo.githubusercontent.com/cf66387a93a8da32eb6e6306a10a32165611cc9c78d52548691c00d1c53100a6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d736f6e7068702f676f6f676c655f7472616e736c6174652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samsonphp/google_translate/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/e75a0520a7b37c63caee91d415dfa957e8c083a778e095b653cfef95fa892617/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e7068702f676f6f676c655f7472616e736c6174652f646f776e6c6f6164732e737667)](https://packagist.org/packages/samsonphp/google_translate)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c9545f91da5e0e346a72a5ffe10e37c5d9e132a76ed5ea7e38600a4ea54f8462/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d736f6e7068702f676f6f676c655f7472616e736c6174652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samsonphp/google_translate/?branch=master)[![Stories in Ready](https://camo.githubusercontent.com/4f347b775e43b2d22a7c3fee75ac23bb74e1e291f8e27957e1b45ae4c420cc71/68747470733a2f2f62616467652e776166666c652e696f2f73616d736f6e7068702f676f6f676c655f7472616e736c6174652e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/samsonphp/google_translate)

\##Configuration

Before using translate module methods, you must create configuration and enter your Google API Key for using Google Translate API

All you need is create configuration class which is working thanks to [SamsonPHP module/service configuration](https://github.com/samsonphp/config):

```
class Google_TranslateConfig extends \samson\core\Config
{
    public $apiKey = 'Your_Google_API_Key';
}
```

Creating translate request
--------------------------

[](#creating-translate-request)

After creating configuration you can make request to Google Translate API. To create simple request you must define source language of your text and target language which you want to get. To identify languages you can use `source($source)` and `target($target)` methods.

For example you want to translate 'Hello World' to french:

```
/** @var \samson\google\Translate $trans Get SamsonPHP GoogleTranslate module */
$trans = & m('google_translate');

// Source text
$helloWorld = 'Hello World';

// Translated text
$bonjourLeMonde = $trans->source('en')->target('fr')->trans($helloWorld);
```

Fixing translation errors
-------------------------

[](#fixing-translation-errors)

If you have some problems with API Key or you have make some errors in defining source or target locales, you will get error from Google Translate API. You can check status of your request using method `lastRequestStatus()`:

```
/** @var \samson\google\Translate $trans Get SamsonPHP GoogleTranslate module */
$trans = & m('google_translate');

// Source text
$helloWorld = 'Hello World';

// Translated text
$bonjourLeMonde = $trans->source('gb')->target('fr')->trans($helloWorld);
echo 'Translated string - "'.$bonjourLeMonde.'"; ';

// Is false, because gb locale is not found in Google language codes.
echo 'Request status is '.$trans->lastRequestStatus();
```

Using this code you will get:

```
Translated string - "Invalid value";
Request status is false

```

Translate array of information using just one request
-----------------------------------------------------

[](#translate-array-of-information-using-just-one-request)

If you need to translate a lot of strings, the best way is define array of your strings as `trans($data)` parameter. Simple example:

```
/** @var \samson\google\Translate $trans Get SamsonPHP GoogleTranslate module */
$trans = & m('google_translate');

// Source strings
$myStrings = array('white dog', 'cat', 'rabbit', 'squirrel');

// Translate it
$myTranslatedStrings = $trans->source('en')->target('fr')->trans($myStrings);

// Look at the response
print_r($myTranslatedStrings);
```

If your Google API Key is active, you will get this data:

```
Array
(
    [white dog] => chien blanc
    [cat] => chat
    [rabbit] => lapin
    [squirrel] => écureuil
)

```

This module is working using [Google Translate API](https://cloud.google.com/translate/)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 59% 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 ~4 days

Total

2

Last Release

4175d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10514779?v=4)[SamsonPHP](/maintainers/samsonphp)[@SamsonPHP](https://github.com/SamsonPHP)

---

Top Contributors

[![onysko](https://avatars.githubusercontent.com/u/7703953?v=4)](https://github.com/onysko "onysko (23 commits)")[![vitalyiegorov](https://avatars.githubusercontent.com/u/586558?v=4)](https://github.com/vitalyiegorov "vitalyiegorov (14 commits)")[![nik-os](https://avatars.githubusercontent.com/u/7326967?v=4)](https://github.com/nik-os "nik-os (2 commits)")

---

Tags

phptranslatesamsonphpsamsonos

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jefs42/libretranslate

PHP interface for the open source LibreTranslate project

3794.7k1](/packages/jefs42-libretranslate)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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