定制 sircoolmind/laravel-ai-translation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sircoolmind/laravel-ai-translation

最新稳定版本:1.0.0

Composer 安装命令:

composer require sircoolmind/laravel-ai-translation

包简介

AI Translation Tool for Laravel using Gemini

README 文档

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.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-23