PHPackages                             fanswoo/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. [Localization &amp; i18n](/categories/localization)
4. /
5. fanswoo/laravel-google-translate

ActiveLibrary[Localization &amp; i18n](/categories/localization)

fanswoo/laravel-google-translate
================================

laravel google translate

0538↓36.4%PHP

Since Mar 28Pushed 9mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Fanswoo/Laravel Google Translate
================================

[](#fanswoolaravel-google-translate)

A comprehensive Laravel package that provides Google Translate functionality with support for both API v2 and v3, plus automated language file translation capabilities.

Features
--------

[](#features)

- **Google Translate API Integration**: Support for both v2 (API key) and v3 (service account) authentication
- **Language File Translation**: Automatically translate Laravel language files using `translate:lang` command
- **Facade Support**: Easy-to-use Laravel facade for translation operations
- **Batch Translation**: Translate multiple texts to multiple target languages
- **Overwrite Protection**: Preserve existing translations while adding new ones
- **Nested Array Support**: Handle complex Laravel language file structures

Requirements
------------

[](#requirements)

- Laravel v11
- PHP ^8.4

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

[](#installation)

You can install the package via composer:

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

After that run the `vendor:publish` command:

```
php artisan vendor:publish --provider=FF\\GoogleTranslate\\GoogleTranslateProvider --tag=config
```

This will publish config from `fanswoo/laravel-google-translate`

Configuration
-------------

[](#configuration)

```
// config/services.php
[
    'google_translate_v2' => [
        'api_key' => env('GOOGLE_TRANSLATE_API_KEY'),
    ],
    'google_translate_v3' => [
        'project_id' => env('GOOGLE_TRANSLATE_PROJECT_ID'),
        'service_account_credentials_path' => env('GOOGLE_TRANSLATE_SERVICE_ACCOUNT_CREDENTIALS_PATH'),
    ],
],
```

```
// config/google-translate.php
return [
    // SSL verification for cURL requests
    'ssl_verify_peer' => true,

    // Google Cloud Version, can be 'v2' or 'v3'
    'api_version' => 'v2'
];
```

Usage
-----

[](#usage)

### Basic Translation

[](#basic-translation)

```
use FF\GoogleTranslate\Facade\Translate;

// Single text translation
$text = Translate::get('hello world', 'zh_TW');

// Multiple texts to multiple languages
$translations = Translate::multiple(['hello', 'world'], ['zh_TW', 'ja_JP']);
```

### Language File Translation Command

[](#language-file-translation-command)

Automatically translate all your Laravel language files:

```
# Translate from English to Traditional Chinese and Japanese
php artisan translate:lang en zh_TW ja_JP

# Overwrite existing translations
php artisan translate:lang en zh_TW --overwrite

# Use custom language directory path
php artisan translate:lang en fr_FR --path=/custom/lang/path
```

**Command Options:**

- `source`: Source locale (e.g., en)
- `targets`: One or more target locales (e.g., zh\_TW ja\_JP fr\_FR)
- `--overwrite`: Overwrite existing translations (default: false)
- `--path`: Custom path to language directory (default: Laravel's lang directory)

### Programmatic Language File Translation

[](#programmatic-language-file-translation)

```
use FF\GoogleTranslate\LocaleTranslation\LocaleTranslation;

$localeTranslation = new LocaleTranslation();

// Translate from 'en' to multiple target locales
$results = $localeTranslation->translate('en', ['zh_TW', 'ja_JP'], false);

// With custom path and overwrite enabled
$results = $localeTranslation->translate('en', ['fr_FR'], true);
```

API Version Configuration
-------------------------

[](#api-version-configuration)

### Google Translate API v2 (Default)

[](#google-translate-api-v2-default)

- Simple API key authentication
- Faster setup
- Suitable for basic translation needs

### Google Translate API v3

[](#google-translate-api-v3)

- Service account authentication
- More secure and feature-rich
- Required for batch operations via `multiple()` method

The package automatically uses v3 for the `multiple()` method regardless of the configured version.

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit
```

The package includes comprehensive tests for:

- Basic translation functionality
- Language file scanning and translation
- Command structure validation
- Error handling and edge cases

Example Language File Structure
-------------------------------

[](#example-language-file-structure)

The package handles Laravel's standard language file structure:

```
// lang/en/messages.php
return [
    'welcome' => 'Welcome to our application',
    'goodbye' => 'Goodbye!',
    'auth' => [
        'failed' => 'These credentials do not match our records.',
        'password' => 'The provided password is incorrect.',
    ],
];
```

After running `php artisan translate:lang en zh_TW`, you'll get:

```
// lang/zh_TW/messages.php
return [
    'welcome' => '歡迎使用我們的應用程式',
    'goodbye' => '再見！',
    'auth' => [
        'failed' => '這些憑據與我們的記錄不符。',
        'password' => '提供的密碼不正確。',
    ],
];
```

License
-------

[](#license)

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

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance40

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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/5e970736787f90b76875d26e5f0359642da86f22b75cd7f558e794155fd351dc?d=identicon)[sacriley](/maintainers/sacriley)

---

Top Contributors

[![sacriley](https://avatars.githubusercontent.com/u/10332688?v=4)](https://github.com/sacriley "sacriley (10 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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