samuelgjekic/laravel-ai-translator
Composer 安装命令:
composer require samuelgjekic/laravel-ai-translator
包简介
AI-powered translation package for Laravel applications using Prism AI
README 文档
README
Laravel AI Translator is a developer tool for scanning and generating translations in Laravel using AI.
Right now it focuses on JSON translations (e.g. lang/en.json) and exports/imports that workflow.
What it does
1) Translate a JSON language file with AI
If you have a lot of keys (e.g. 3000+), you can translate them into a new language using a single Artisan command.
Example: translate en.json → Swedish:
php artisan translate:language swedish
Under the hood the package:
- reads your source JSON (default is configurable)
- splits it into chunks
- securely translates a few keys at a time
- writes the final translated JSON file (e.g.
sv.json)
2) Scan your app/views and generate a JSON file of translation keys
If you don’t already have a JSON file with all your keys, you can generate one by scanning your codebase:
php artisan translations:export
You can also override the output location:
php artisan translations:export --output=path/to/export.json
The scanner looks through your configured paths (app + views by default) and extracts translation keys from:
__('...'),@lang('...'),trans('...'),Lang::get('...')- keys with parameters like
__('Items total: :count', ['count' => ...]) - placeholders/variables like
:count,{count},{{name}}, etc.
Variables/placeholders are preserved by the AI translator and should not be translated.
Installation
composer require samuelgjekic/laravel-ai-translator
Publish config (recommended):
php artisan vendor:publish --tag=ai-translator-config
Configuration
AI credentials (Prism)
This package uses Prism under the hood. Set your provider keys the way Prism expects.
Example for OpenAI:
OPENAI_API_KEY=your-api-key
Provider + model
You can switch provider/model via env:
AI_TRANSLATOR_PROVIDER=openai AI_TRANSLATOR_MODEL=gpt-5-mini
Package config
After publishing config/ai-translator.php, you can configure:
- default
source_language(e.g.en) - chunk size
- queue/job settings (tries, timeout, delays)
- scanning paths and export path
- regex patterns for key detection
The most important config block is:
'paths' => [ // Directory for translation JSON files. null = use Laravel's default lang_path() 'translations' => null, // Default export file for the scanner (relative to base_path()) 'export' => 'lang/export.json', // What to scan when running translations:export 'scan' => [ 'app', 'resources/views', ], ],
Usage
Translate language files
Translate using queue jobs (recommended):
php artisan translate:language swedish
Specify a custom source file (without .json):
php artisan translate:language swedish --source=en
Run without jobs (not recommended, but useful for quick testing):
php artisan translate:language swedish --sync
Translate only a few chunks (useful for testing prompts / rate limiting):
php artisan translate:language swedish --chunks=3
Scan & export keys
Scan your app + views (configured in paths.scan) and export a key JSON:
php artisan translations:export
Override output file:
php artisan translations:export --output=myfolder/keys.json
Notes / current limitations
- Currently JSON translations only (
lang/*.json). - The translator has been tested on 5000+ keys, including keys with variables/placeholders, across multiple languages.
- Translating large files can take time depending on queue throughput, rate limits, and key count.
- More support for other Laravel translation styles (arrays, vendor files, etc.) is coming.
Contributing
PRs are welcome.
If you’d like to add more scanning patterns, improve prompts, add support for array-based translations, or add tests—jump in.
License
MIT. See LICENSE.md.
samuelgjekic/laravel-ai-translator 适用场景与选型建议
samuelgjekic/laravel-ai-translator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「translation」 「laravel」 「localization」 「prism」 「ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samuelgjekic/laravel-ai-translator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samuelgjekic/laravel-ai-translator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samuelgjekic/laravel-ai-translator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
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
Nette Framework adapter for I18n package
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-20