sircoolmind/laravel-ai-translation

AI Translation Tool for Laravel using Gemini

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 1

pkg:composer/sircoolmind/laravel-ai-translation

1.0.0 2025-12-23 07:10 UTC

This package is auto-updated.

Last update: 2025-12-24 09:45:55 UTC


README

This package automates your Laravel localization process. It uses Google Gemini AI to automatically translate your language keys from English to other supported languages (e.g., Malay, Chinese) and saves them directly to your JSON language files (lang/ms.json, lang/zh_CN.json, etc.).

It comes with a built-in UI, a Command Line tool, and a Facade for programmatic usage.

Installation

You can install the package via composer:

composer require sircoolmind/laravel-ai-translation

1. Publish Configuration

Publish the configuration file to setup your API keys and supported languages.

php artisan vendor:publish --tag="ai-translation-config"

2. Configure API Key

Open your .env file and add your Google Gemini API Key:

GEMINI_API_KEY=your_api_key_here

You can also customize supported languages in config/ai-translation.php.

Usage

1. Via Visual Interface (UI)

This package comes with a built-in dashboard to manage translations easily.

  1. Open your browser and visit: http://your-app.test/ai-translations
  2. Enter a Key (e.g., welcome_message) and the Word (e.g., "Welcome to our system").
  3. Click Auto Translate.
  4. The system will generate translations for all configured languages and save them to your JSON files.

2. Via Command Line (CLI)

Perfect for developers who want to add translations quickly without leaving the terminal.

Syntax:

php artisan ai-translator-lang {key} "{word}"

Example: Translate "Dashboard" to all supported languages:

php artisan ai-translator-lang dashboard_title "Dashboard"

Override Source Language: If your input word is in Malay:

php artisan ai-translator-lang dashboard_title "Papan Pemuka" --source=ms

3. Via Facade (Code)

You can use the AiTranslator facade inside your Controllers, Jobs, or Seeders to trigger translations programmatically.

use SirCoolMind\AiTranslation\Facades\AiTranslator;

public function store(Request $request) 
{
    // ... create product logic ...

    // Automatically translate the success message
    AiTranslator::translateAndSave('product_created', 'Product created successfully');

    return back();
}

Configuration (config/ai-translation.php)

return [
    // Default source language for input
    'source_locale' => 'en',

    // Languages to translate into
    'supported_locales' => ['en', 'ms', 'zh'],

    // Mapping Laravel locales to Google Translate codes
    'google_map' => [
        'zh' => 'zh-CN',
        'ms' => 'ms',
    ],

    'api_key' => env('GEMINI_API_KEY'),
];

Testing

To run the test suite included in this package:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

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