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

ActiveLibrary[API Development](/categories/api)

dstuchbury/laravel-google-translate
===================================

Laravel package for the Google Translate API

9.02(3mo ago)11.9kMITPHPPHP ^8.2CI passing

Since Oct 23Pushed 3mo agoCompare

[ Source](https://github.com/dstuchbury/laravel-google-translate)[ Packagist](https://packagist.org/packages/dstuchbury/laravel-google-translate)[ RSS](/packages/dstuchbury-laravel-google-translate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (26)Used By (0)

Laravel package for the Google Translate API
============================================

[](#laravel-package-for-the-google-translate-api)

This is a fork of  - I did not create this package originally and take no credit for it.

The composer.json `authors` element has been modified accordingly.

[![](https://github.com/dstuchbury/laravel-google-translate/workflows/Run%20Tests/badge.svg?branch=master)](https://github.com/dstuchbury/laravel-google-translate/workflows/Run%20Tests/badge.svg?branch=master)

This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.

[![translate](https://user-images.githubusercontent.com/11228182/47329451-5ede5b00-d692-11e8-9709-bfeadd0a9d91.png)](https://user-images.githubusercontent.com/11228182/47329451-5ede5b00-d692-11e8-9709-bfeadd0a9d91.png)

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

[](#installation)

- You can install this package via composer using this command:

```
composer require dstuchbury/laravel-google-translate
```

- The package will automatically register itself.
- We have documented how to setup the project and get the necessary configurations from the Google Cloud Platform console in a step by step detailed manner [over here.](https://github.com/dstuchbury/laravel-google-translate/blob/master/google.md)
- You can publish the config file using the following command:

```
php artisan vendor:publish --provider="dstuchbury\GoogleTranslate\GoogleTranslateServiceProvider"
```

This will create the package's config file called `googletranslate.php` in the `config` directory. These are the contents of the published config file:

```
return [
    /*
    |----------------------------------------------------------------------------------------------------
    | The ISO 639-1 code of the language in lowercase to which the text will be translated to by default.
    |----------------------------------------------------------------------------------------------------
    */
    'default_target_translation' => 'en',

    /*
    |-------------------------------------------------------------------------------
    | Path to the json file containing the authentication credentials.
    |
    | The process to get this file is documented in a step by step detailed manner
    | over here:
    | https://github.com/dstuchbury/laravel-google-translate/blob/master/google.md
    |-------------------------------------------------------------------------------
    */
    'api_key' => env('GOOGLE_TRANSLATE_API_KEY'),
];
```

How to use
----------

[](#how-to-use)

- After setting up the config file values you are all set to use the following methods 😄
- Detecting the language. You can pass both, a single string or an array of multiple strings to it:

```
GoogleTranslate::detectLanguage('Hello world'): array

GoogleTranslate::detectLanguage(['Hello world', 'Laravel is the best']);

// Returns multi-dimensional array containing result set for all the array elements.
```

- Translating the string(s): The `translate` method accepts a third optional argument which can be the code of the language you want the string to be translated in. You can specify the default option in the config file:

```
// GoogleTranslate::translate($input, $from = null, $to = null, $format = 'text'): array

GoogleTranslate::translate('Hello world'): array

GoogleTranslate::translate(['Hello world', 'Laravel is the best']);

// Returns multi-dimensional array containing result set for all the array elements.
```

- Get all the available translations from 'Google Translation' for a particular language by passing its language code:

```
GoogleTranslate::getAvailableTranslationsFor('en'): array
```

- Translate unless the language is same as the first argument. This method is a clean way to ask the package to detect the language of the given string, if it is same as the first argument, translation isn't performed. It accepts an optional third argument which is the language code you want the string to be translated in. You can specify the default option in the config file. If the languages are same, the input string is returned as it is, else an array is returned containing the translation results:

```
GoogleTranslate::unlessLanguageIs('en', string $text);
```

- Translating and just returning back the translated string. It accepts an optional second argument which is the language code you want the string to be translated in. You can specify the default option in the config file.

```
GoogleTranslate::justTranslate(string $text): string
```

- There is is an optional third parameter for format to take advantage for better html translation support. Google Translate API currently supports 'text' and 'html' as parameters. The default for this parameter is 'text' as it has the best use case for most translations. [Google Translate API Docs](https://cloud.google.com/translate/docs/reference/rest/v2/translate)

```
GoogleTranslate::unlessLanguageIs('en', string $text, string $format);
```

- There is also a nice blade helper called `@translate` that comes with the package to make its use more neat in the view files. It accepts an optional second argument which is the language code you want the string to be translated in. You can specify the default option in the config file.

```
@translate('Hello World')

```

Testing
-------

[](#testing)

You can run the tests with:

```
vendor/bin/phpunit
```

Changelog
---------

[](#changelog)

Please see the [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email them to [dan@danstuchbury](mailto:dan@danstuchbury.com) instead of using the issue tracker.

Credits
-------

[](#credits)

- [Harish Toshniwal](https://github.com/introwit)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE.txt) for more information.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance80

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 65.1% 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 ~110 days

Recently: every ~323 days

Total

25

Last Release

106d ago

Major Versions

v5.0.2 → v6.0.02020-09-10

v6.0.1 → v7.0.02021-01-24

v7.0.0 → v8.0.02022-03-07

v8.1.0 → v9.0.02023-01-02

v7.0.1 → 9.022026-01-27

PHP version history (5 changes)v1.0.0PHP ^7.2

v5.0.0PHP ^7.3

v7.0.0PHP ^7.4|^8.0

v8.0.0PHP ^8.0

9.02PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b9ba3dfe24ac53d481acb478a2c296453ce0f0db7b45353afb0ef3a7d4d3166b?d=identicon)[dstuchbury](/maintainers/dstuchbury)

---

Top Contributors

[![introwit](https://avatars.githubusercontent.com/u/11228182?v=4)](https://github.com/introwit "introwit (41 commits)")[![resslinger](https://avatars.githubusercontent.com/u/6031484?v=4)](https://github.com/resslinger "resslinger (15 commits)")[![josiasmontag](https://avatars.githubusercontent.com/u/1945577?v=4)](https://github.com/josiasmontag "josiasmontag (2 commits)")[![jaric](https://avatars.githubusercontent.com/u/86606?v=4)](https://github.com/jaric "jaric (2 commits)")[![gcorreaalves](https://avatars.githubusercontent.com/u/983426?v=4)](https://github.com/gcorreaalves "gcorreaalves (1 commits)")[![rusdyahmad](https://avatars.githubusercontent.com/u/488866?v=4)](https://github.com/rusdyahmad "rusdyahmad (1 commits)")[![smorris1709](https://avatars.githubusercontent.com/u/11929317?v=4)](https://github.com/smorris1709 "smorris1709 (1 commits)")

---

Tags

apilaraveltranslategooglepackagegoogle-translate

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[mbarwick83/shorty

Google Url Shortener API Package for Laravel 5.1

31204.9k](/packages/mbarwick83-shorty)[gregoriohc/laravel-trello

A Laravel wrapper and facade package for the Trello API

3366.8k2](/packages/gregoriohc-laravel-trello)[vinelab/api-manager

Laravel API Manager Package - beatify and unify your responses with the least effort possible.

392.1k](/packages/vinelab-api-manager)

PHPackages © 2026

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