iperamuna/laravel-auto-translations
最新稳定版本:v0.0.1
Composer 安装命令:
composer require iperamuna/laravel-auto-translations
包简介
Auto-generate JSON language files, AI translations, and a local-only language browser.
README 文档
README
✨ Automatically scan your Laravel app for translation keys, export them to JSON, generate translations via OpenAI, and preview them in a simple local browser UI.
🚀 Features
- 🔍 Scan your entire Laravel app for
__('...')usage - 🧠 Generate translated JSON files via OpenAI (e.g.,
en.json→es.json) - 🌐 Local-only language preview UI (
/langs) - 🔄 Export to nested i18n format (
lang:export-i18n) for Vue or frontend use - 🗃️ Offline caching of AI translations to avoid repeated costs
- ✅ Fully extendable, no frontend JS frameworks required
📦 Installation
composer require iperamuna/laravel-auto-translations php artisan vendor:publish --tag=auto-translations-config
Make sure you have OPENAI_API_KEY in your .env:
AUTO_TRANSLATE_REMOTE_VIEW_ENABLED=false AUTO_TRANSLATE_REMOTE_VIEW_TOKEN=/*any*/ AUTO_TRANSLATE_OPENAI_API_BASE=https://api.groq.com/openai/v1 AUTO_TRANSLATE_OPENAI_MODEL=meta-llama/llama-4-scout-17b-16e-instruct AUTO_TRANSLATE_OPENAI_API_KEY=gsk_..
🛠️ Artisan Commands
# 🔍 Scan your app and generate en.json php artisan lang:generate-en-json # 🌍 Create a new translation using AI php artisan lang:new es --preview # 🧱 Export to nested format (e.g., for Vue i18n) php artisan lang:export-i18n en
🌐 Local Language Browser
Access this route in APP_ENV=local:
http://localhost:8000/langs
Note: This route is only registered in
localenvironment.
- View translations from any existing
.jsonlanguage file - Switch between languages with a dropdown
- Built using Tailwind CSS (via CDN)
- Can do remote view enabling AUTO_TRANSLATE_REMOTE_VIEW_ENABLED=true and setting up token by AUTO_TRANSLATE_REMOTE_VIEW_TOKEN
http://{remote.host.url}/langs?_token=***
📁 Output Examples
en.json (flat)
{
"auth.login": "Login",
"profile.edit": "Edit Profile"
}
en.i18n.json (nested)
{
"auth": {
"login": "Login"
},
"profile": {
"edit": "Edit Profile"
}
}
📚 Configuration
Publish the config:
php artisan vendor:publish --tag=auto-translations-config
You can configure:
<?php return [ 'remote' => [ 'enabled' => env('AUTO_TRANSLATE_REMOTE_VIEW_ENABLED', false), 'token' => env('AUTO_TRANSLATE_REMOTE_VIEW_TOKEN', ''), ], 'paths' => [ base_path('resources/js'), ], 'ai' => [ 'enabled' => env('AUTO_TRANSLATE_ENABLED', true), 'api_key' => env('AUTO_TRANSLATE_OPENAI_API_KEY', ''), 'api_base' => env('AUTO_TRANSLATE_OPENAI_API_BASE', 'https://api.groq.com/openai/v1'), 'model' => env('AUTO_TRANSLATE_OPENAI_MODEL', 'gpt-4o-mini'), 'temp' => env('AUTO_TRANSLATE_TEMPERATURE', 0.3), 'chunk' => env('AUTO_TRANSLATE_CHUNK_SIZE', 50), ], ]; ];
🤖 AI Translation Strategy
- Uses OpenAI Chat API (
gpt-4o,gpt-3.5, etc.) - Can Use Groak Api too
- Breaks translations into chunks
- Prompts ChatGPT to preserve keys, variables (
:name,:count, etc.) - Saves translated output as
es.json,fr.json, etc.
📜 License
This package is open-source software licensed under the MIT license.
🙋♀️ Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
📣 Credits
Made with ❤️ by Indunil Peramuna
Built for Laravel developers who love clean translation management.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-16