PHPackages                             anuragsingk/laravel-ai-translator - 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. anuragsingk/laravel-ai-translator

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

anuragsingk/laravel-ai-translator
=================================

A Laravel package for AI-powered language file translation using Google Gemini.

1.0.0(1y ago)17MITPHPPHP &gt;=8.1

Since Jun 25Pushed 1y agoCompare

[ Source](https://github.com/anuragsingk/laravel-ai-translator)[ Packagist](https://packagist.org/packages/anuragsingk/laravel-ai-translator)[ Docs](https://github.com/anuragsingk/laravel-ai-translator)[ RSS](/packages/anuragsingk-laravel-ai-translator/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel AI Translator
=====================

[](#laravel-ai-translator)

[![Laravel AI Translator Screenshot](https://camo.githubusercontent.com/9b1cd21059eadad482122c03e5da24d63e183a8d811de550baf2e942b31e9b2e/68747470733a2f2f692e6962622e636f2f634d6b4a7451632f53637265656e73686f742d323032352d30362d32352d3131323132312e706e67)](https://camo.githubusercontent.com/9b1cd21059eadad482122c03e5da24d63e183a8d811de550baf2e942b31e9b2e/68747470733a2f2f692e6962622e636f2f634d6b4a7451632f53637265656e73686f742d323032352d30362d32352d3131323132312e706e67)

**Laravel AI Translator** is a powerful package designed to automate the translation of your application's language files using **Google Gemini AI Studio API**. It simplifies your localization workflow, letting you scale your app to multiple languages with ease and precision.

---

✨ Features
----------

[](#-features)

- **AI-Powered Translations**
    High-quality, context-aware translations powered by Google Gemini AI.
- **Dual File Support**
    Automatically translates both JSON files (`resources/lang/en.json`) and PHP array files (`resources/lang/en/messages.php`).
- **Smart Updates**
    Detects and translates only missing or identical keys, preserving your custom edits.
- **Structured Arrays Preserved**
    Maintains the original structure of nested PHP arrays without any flattening.
- **Interactive CLI**
    Artisan commands make setup, translation, and management intuitive and fast.
- **Dry Run Mode**
    Preview translations directly in the console before saving them.
- **Configurable &amp; Extensible**
    Customize API keys, source/target languages, and AI prompts via config file.
- **Laravel Ready**
    Compatible with Laravel 10.x, 11.x and PHP &gt;= 8.1.
- **Robust Error Handling**
    Graceful messaging for API errors and misconfigurations.

---

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require anuragsingk/laravel-ai-translator
```

---

🛠️ Setup
--------

[](#️-setup)

Before you begin, you’ll need a **Google Gemini API Key**.
👉 [Generate your API Key from Google AI Studio](https://aistudio.google.com/apikey)

After that, run the setup command to configure the package:

```
php artisan ai-translate:setup
```

This command will:

1. Prompt for your Gemini API key (saved as `AI_TRANSLATOR_API_KEY` in `.env`)
2. Auto-detect source language files (e.g., `en.json`, `en/messages.php`)
3. Attempt to auto-detect the source language (e.g., `en`) and confirm it

*Optional*: To manually publish the configuration file:

```
php artisan vendor:publish --tag=ai-translator-config
```

---

📖 Usage
-------

[](#-usage)

### Add a New Language

[](#add-a-new-language)

```
php artisan ai-translate:add-language es
```

Translates your source language files into a new target language (e.g., Spanish `es`) and saves them as:

- `resources/lang/es.json`
- `resources/lang/es/messages.php`

---

### Update Existing Translations

[](#update-existing-translations)

```
php artisan ai-translate:update
```

Updates all configured target languages by translating only missing or unchanged keys.

---

### Preview (Dry Run)

[](#preview-dry-run)

```
php artisan ai-translate:update --dry-run
```

Previews the translations in your console without writing to any files.

---

### Delete a Language

[](#delete-a-language)

```
php artisan ai-translate:delete-language ta
```

Deletes all language files associated with a specific language code.

---

### List Configured Languages

[](#list-configured-languages)

```
php artisan ai-translate:list
```

Displays source and target languages and associated files.

---

### Show Current Configuration

[](#show-current-configuration)

```
php artisan ai-translate:show-config
```

Displays the current configuration (API key masked).

---

📂 File Handling
---------------

[](#-file-handling)

### JSON File Example

[](#json-file-example)

```
{
    "welcome": "Welcome to our application!",
    "greeting": "Hello, {name}!",
    "messages": {
        "success": "Operation completed successfully.",
        "error": "An error occurred."
    }
}
```

### PHP Array File Example

[](#php-array-file-example)

```
