anuragsingk/laravel-ai-translator
Composer 安装命令:
composer require anuragsingk/laravel-ai-translator
包简介
A Laravel package for AI-powered language file translation using Google Gemini.
关键字:
README 文档
README
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
-
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 & Extensible
Customize API keys, source/target languages, and AI prompts via config file. -
Laravel Ready
Compatible with Laravel 10.x, 11.x and PHP >= 8.1. -
Robust Error Handling
Graceful messaging for API errors and misconfigurations.
🚀 Installation
Install the package via Composer:
composer require anuragsingk/laravel-ai-translator
🛠️ Setup
Before you begin, you’ll need a Google Gemini API Key.
👉 Generate your API Key from Google AI Studio
After that, run the setup command to configure the package:
php artisan ai-translate:setup
This command will:
- Prompt for your Gemini API key (saved as
AI_TRANSLATOR_API_KEYin.env) - Auto-detect source language files (e.g.,
en.json,en/messages.php) - 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
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.jsonresources/lang/es/messages.php
Update Existing Translations
php artisan ai-translate:update
Updates all configured target languages by translating only missing or unchanged keys.
Preview (Dry Run)
php artisan ai-translate:update --dry-run
Previews the translations in your console without writing to any files.
Delete a Language
php artisan ai-translate:delete-language ta
Deletes all language files associated with a specific language code.
List Configured Languages
php artisan ai-translate:list
Displays source and target languages and associated files.
Show Current Configuration
php artisan ai-translate:show-config
Displays the current configuration (API key masked).
📂 File Handling
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 return [ 'welcome_message' => 'Welcome to our website!', 'goodbye_message' => 'Goodbye, see you soon!', 'validation' => [ 'required' => 'The :attribute field is required.', 'email' => 'The :attribute must be a valid email address.', ], ];
The package maintains file structure and nesting in both formats.
🧭 Roadmap
- ✅ Enhanced interactive CLI experience
- ✅ Dry run mode for safe previews
- 🔜 Native PHP support (without Laravel dependency)
- 🔜 Inline review & editing before saving translations
- 🔜 Support for alternative APIs: OpenAI, DeepSeek, Google Translate, DeepL
- 🔜 File merge options before translation
- 🔜 Detailed logging to
storage/logs/ai-translator.log - 🔜 Explicit option to skip unchanged keys
- 🔜 Per-file custom AI prompts
- 🔜 Comprehensive test suite
🤝 Contributing
Contributions are welcome! To contribute:
- Fork the repo
- Create a feature branch
- Make your changes and commit
- Write tests (if applicable)
- Open a Pull Request to
main
For local development, link the package using Composer's path repository feature:
"repositories": [ { "type": "path", "url": "../path/to/your/local/laravel-ai-translator" } ], "require": { "anuragsingk/laravel-ai-translator": "*" }
Then run:
composer update
anuragsingk/laravel-ai-translator 适用场景与选型建议
anuragsingk/laravel-ai-translator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「translation」 「laravel」 「ai」 「Gemini」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 anuragsingk/laravel-ai-translator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anuragsingk/laravel-ai-translator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 anuragsingk/laravel-ai-translator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Laravel Eloquent model trait for translatable resource
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Symfony localise.biz library
This bundle provides translations for entities in your project. It's a bundle, but can be used standalone.
Checks if all translation items appear in all languages
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-25