eii/laravel-ai-locale-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

eii/laravel-ai-locale-generator

Composer 安装命令:

composer require eii/laravel-ai-locale-generator

包简介

AI powered localization generator for Laravel

README 文档

README

AI-powered localization generator for Laravel applications.
Automatically extracts texts from Blade files, generates locale keys, optionally translates to multiple languages, and safely updates your Blade files.

Features

  • Extract texts from Blade files and generate locale keys
  • AI-assisted key generation (OpenAI)
  • Translation support (Google Translate & DeepL)
  • Multi-language locale PHP files (resources/lang/en/*.php, ja, es, etc.)
  • Safe Blade rewriting with optional backup
  • Dot notation support (welcome, auth.login) for Blade files
  • Fully configurable via config/ai-locale-generator.php
  • CLI commands for automated workflows

Installation

composer require eii/laravel-ai-locale-generator

Publish the config file:

php artisan vendor:publish --tag=ai-locale-generator-config

Update your .env with API keys:

OPENAI_API_KEY=sk-xxx
GOOGLE_TRANSLATE_API_KEY=xxx
DEEPL_API_KEY=xxx

Configuration

config/ai-locale-generator.php:

return [
    'provider' => 'openai',
    'api_key' => env('OPENAI_API_KEY'),
    'model' => 'gpt-4o-mini',

    'translator' => 'google', // options: 'google', 'deepl'
    'google_api_key' => env('GOOGLE_TRANSLATE_API_KEY'),
    'deepl_api_key' => env('DEEPL_API_KEY'),
    
    'backup' => true, // default: backup Blade files before applying
];

Commands

1. Generate Locale Files

php artisan locale:generate <blade_file> [--lang=ja,es]
  • Extracts texts from the Blade file
  • Creates source language file resources/lang/en/<blade>.php automatically
  • Translates to languages specified in --lang (optional)
  • Example:
php artisan locale:generate welcome --lang=ja,es

2. Apply Keys to Blade

php artisan locale:apply <blade_file> [--backup|--no-backup]
  • Replaces original texts with locale keys
  • Uses APP_LOCALE as source language
  • Optional backup (.bak) before rewriting
  • Example:
php artisan locale:apply welcome auth.login --backup

Usage Notes

  • Source language is always your APP_LOCALE (.env).
  • Translation languages are optional.
  • Currently does not handle dynamic variables in texts (e.g., :count). Planned for future release.
  • Supports both single and double-quoted Blade translations.

Example Workflow

  1. Generate keys & translations:
php artisan locale:generate welcome --lang=ja,es
  1. Manually edit translations if needed:
// resources/lang/ja/welcome.php
'welcome_message' => 'ようこそ',
  1. Apply keys to Blade:
php artisan locale:apply welcome
  1. Now your Blade file uses:
{{ __('welcome.welcome_message') }}

Requirements

  • PHP 8.1+
  • Laravel 9.0, 10.0, 11.0, 12.0
  • Google Translate API V2 (for google provider)
  • DeepL API (for deepl provider)

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固