PHPackages                             naimkhalifa/laravel-google-cloud-translation - 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. naimkhalifa/laravel-google-cloud-translation

ActiveLibrary[API Development](/categories/api)

naimkhalifa/laravel-google-cloud-translation
============================================

A package to easily integrate Google Cloud Translation API with Laravel

0.3.1(2y ago)058[3 PRs](https://github.com/naimkhalifa/laravel-google-cloud-translation/pulls)MITPHPPHP ^8.1

Since Sep 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/naimkhalifa/laravel-google-cloud-translation)[ Packagist](https://packagist.org/packages/naimkhalifa/laravel-google-cloud-translation)[ Docs](https://github.com/naimkhalifa/laravel-google-cloud-translation)[ RSS](/packages/naimkhalifa-laravel-google-cloud-translation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (10)Used By (0)

A package to easily integrate Google Cloud Translation API with Laravel
=======================================================================

[](#a-package-to-easily-integrate-google-cloud-translation-api-with-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bc9f7aa62080f6c7e0a0691a1a8b727e3ff6480cb168640eeb8f12e86645b60f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e61696d6b68616c6966612f6c61726176656c2d676f6f676c652d636c6f75642d7472616e736c6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/naimkhalifa/laravel-google-cloud-translation)[![GitHub Tests Action Status](https://camo.githubusercontent.com/49a5ce23dce8f3b4a3ecafa3c08a4b252ba936de7a53607eb7184a219a2e04fa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e61696d6b68616c6966612f6c61726176656c2d676f6f676c652d636c6f75642d7472616e736c6174696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/naimkhalifa/laravel-google-cloud-translation/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/c5f8070281b84b1d1432d0b9f93ca821d2904d7ddb10948dc3f9aa82a73fe8fc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e61696d6b68616c6966612f6c61726176656c2d676f6f676c652d636c6f75642d7472616e736c6174696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/naimkhalifa/laravel-google-cloud-translation/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/45b67845e332ce39b87bab9dd20653d56b7f0c273af425c8e4ebfedc670e9ed2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e61696d6b68616c6966612f6c61726176656c2d676f6f676c652d636c6f75642d7472616e736c6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/naimkhalifa/laravel-google-cloud-translation)

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

[](#installation)

You can install the package via composer:

```
composer require naimkhalifa/laravel-google-cloud-translation
```

You can publish the config file with:

```
php artisan vendor:publish --provider="NaimKhalifa\GoogleCloudTranslation\GoogleCloudTranslationServiceProvider"
```

This is the contents of the published config file:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Google Cloud Translation API Key
    |--------------------------------------------------------------------------
    |
    | Your Google Cloud Translation API Key.
    | You can get it from https://console.cloud.google.com/apis/credentials
    | More info at https://cloud.google.com/translate/docs/setup
    |
    */
    'api_key' => env('GOOGLE_CLOUD_TRANSLATION_API_KEY'),

    /*
    |--------------------------------------------------------------------------
    | Default Source Language
    |--------------------------------------------------------------------------
    |
    | The default source language to translate from.
    | You can find the list of supported languages here:
    | https://cloud.google.com/translate/docs/languages
    |
    */
    'default_source_language' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Default Target Language
    |--------------------------------------------------------------------------
    |
    | The default target language to translate to.
    | Obviously, it must be different from the default source language.
    |
    */
    'default_target_language' => 'es',

    /*
    |--------------------------------------------------------------------------
    | Default Format
    |--------------------------------------------------------------------------
    |
    | The default format to translate to.
    | Acceptable values are html or text.
    |
    */
    'default_format' => 'text',
];
```

Usage
-----

[](#usage)

#### GoogleCloudTranslation::translate(string $text, array $options)

[](#googlecloudtranslationtranslatestring-text-array-options)

Use this method if you want to translate a single text string.

```
# This would translate using default_source_language
# and default_target_language config values
GoogleCloudTranslation::translate('Hello World');

# with options
GoogleCloudTranslation::translate('Hello World', [
  'source' => 'en',
  'target' => 'fr',
  'format' => 'text', # or 'html'
]);
```

#### GoogleCloudTranslation::translateBatch(array $input, array $options)

[](#googlecloudtranslationtranslatebatcharray-input-array-options)

Use this method if you want to translate multiple strings at once.

```
GoogleCloudTranslation::translateBatch([
  'Something else',
  'Another string to translate',
  'And a third one because we can'
])

# You can also pass options to this method
GoogleCloudTranslation::translateBatch('Hello World', [
  'source' => 'en',
  'target' => 'fr',
  'format' => 'text', # or 'html'
]);
```

Commands
--------

[](#commands)

### Translate language files

[](#translate-language-files)

This Artisan command allows you to translate strings in a language file using Google Cloud Translation.
The format of the file you want to translate should conform to what you would typically find under Laravel `/lang` folder.

```
php artisan google-cloud-translation:translate-lang-file [options]

```

#### Options

[](#options)

`--source`: Specify the source language for translation. (**Required**)
`--target`: Specify the target language for translation. (**Required**)
`--file`: Specify the path to the language file you want to translate. (**Required**)
`--dryrun`: Enable dry run mode, which will display translations without saving them to a file. (Optional, enabled by default)

#### Example

[](#example)

```
php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php

```

This is when you're running the command with --dryrun option enabled (by default).
This command will translate all the strings in the messages.php language file from English (en) to French (fr) and display the translations on the terminal.
You then have to confirm with prompt for the translations to be saved to destination file (in this example, that would be `resources/lang/fr/messages.php`).

Be careful that this will override any existing file that lives at that path! Basically replacing it.

If you want to bypass confirmation and directly write to destination, you can disable dryrun mode (`--dryrun=false`)

```
php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php --dryrun=false

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Naïm Khalifa](https://github.com/naimkhalifa)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.4% 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 ~0 days

Total

6

Last Release

957d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f646a906aad1c881847963a4059e75b1cd8d524598c46f52aafcb23b45aafb9?d=identicon)[naimkhalifa](/maintainers/naimkhalifa)

---

Top Contributors

[![naimkhalifa](https://avatars.githubusercontent.com/u/7080564?v=4)](https://github.com/naimkhalifa "naimkhalifa (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

laravelnaimkhalifalaravel-google-cloud-translation

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/naimkhalifa-laravel-google-cloud-translation/health.svg)

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

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.0k7.8M57](/packages/dedoc-scramble)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[combindma/laravel-facebook-pixel

Meta pixel integration for Laravel

4956.9k](/packages/combindma-laravel-facebook-pixel)[stechstudio/laravel-hubspot

A Laravel SDK for the HubSpot CRM Api

2971.0k](/packages/stechstudio-laravel-hubspot)[njoguamos/laravel-plausible

A laravel package for interacting with plausible analytics api.

208.8k](/packages/njoguamos-laravel-plausible)

PHPackages © 2026

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