PHPackages                             megajdcc/lg-translater - 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. megajdcc/lg-translater

ActiveLibrary[API Development](/categories/api)

megajdcc/lg-translater
======================

Laravel package for the Google Translate API

v1.0.8(2mo ago)032MITPHPPHP ^8.2|^8.3|^8.4

Since Sep 29Pushed 2mo agoCompare

[ Source](https://github.com/megajdcc/lg-translater)[ Packagist](https://packagist.org/packages/megajdcc/lg-translater)[ RSS](/packages/megajdcc-lg-translater/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (11)Used By (0)

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

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

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 megajdcc/lg-translater
```

- 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/megajdcc/laravel-google-translate/blob/master/google.md)
- You can publish the config file using the following command:

```
php artisan vendor:publish --provider="Megajdcc\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/megajdcc/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  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jhonatan Crespo](https://github.com/megajdcc)

License
-------

[](#license)

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

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance84

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 57.7% 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 ~109 days

Recently: every ~218 days

Total

9

Last Release

83d ago

PHP version history (4 changes)v1.0.0PHP ^8.2

v1.0.4PHP ^8.1|^8.2

v1.0.5PHP ^8.2|^8.3

v1.0.8PHP ^8.2|^8.3|^8.4

### Community

Maintainers

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

---

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)")[![megajdcc](https://avatars.githubusercontent.com/u/29239993?v=4)](https://github.com/megajdcc "megajdcc (8 commits)")[![jaric](https://avatars.githubusercontent.com/u/86606?v=4)](https://github.com/jaric "jaric (2 commits)")[![josiasmontag](https://avatars.githubusercontent.com/u/1945577?v=4)](https://github.com/josiasmontag "josiasmontag (2 commits)")[![smorris1709](https://avatars.githubusercontent.com/u/11929317?v=4)](https://github.com/smorris1709 "smorris1709 (1 commits)")[![rusdyahmad](https://avatars.githubusercontent.com/u/488866?v=4)](https://github.com/rusdyahmad "rusdyahmad (1 commits)")[![gcorreaalves](https://avatars.githubusercontent.com/u/983426?v=4)](https://github.com/gcorreaalves "gcorreaalves (1 commits)")

---

Tags

apilaraveltranslategooglepackagegoogle-translate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/megajdcc-lg-translater/health.svg)

```
[![Health](https://phpackages.com/badges/megajdcc-lg-translater/health.svg)](https://phpackages.com/packages/megajdcc-lg-translater)
```

###  Alternatives

[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[bmatovu/laravel-mtn-momo

Laravel MTN MOMO integration.

14310.9k](/packages/bmatovu-laravel-mtn-momo)[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)
