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

0806↓64.2%PHP

Since Mar 28Pushed 3mo 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 today

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

23

—

LowBetter than 26% of packages

Maintenance55

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

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://avatars.githubusercontent.com/u/10332688?v=4)[Yi Yang](/maintainers/sacriley)[@sacriley](https://github.com/sacriley)

---

Top Contributors

[![sacriley](https://avatars.githubusercontent.com/u/10332688?v=4)](https://github.com/sacriley "sacriley (12 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

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1927.0k1](/packages/smmoosavi-php-gettext)[saeven/circlical-po-editor

Gettext \*.PO file editor and parser for PHP.

118.1k1](/packages/saeven-circlical-po-editor)

PHPackages © 2026

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