aavinseth/laravel-translate
最新稳定版本:1.0
Composer 安装命令:
composer require aavinseth/laravel-translate
包简介
Automatically translate your Laravel language files using Google Translate or DeepL
README 文档
README
With this package you can translate your language files using a translator service. The package ships with a free Google Translate version, the Google Cloud Translate API and DeepL.
Specify a source language and a target language and it will automatically translate your files. This is useful if you want to prototype something quickly or just get a first idea of the translation for later editing. The package ships with two artisan commands. One for translating all the missing translations that are set in the source language but not in the target language. The other one for translating all source language files and overwriting everything in the target language.
This package is a maintained fork of
ben182/laravel-auto-translate, updated to support Laravel 11, 12 and 13 on PHP 8.2+. The abandonedthemsaid/laravel-langmandependency has been vendored into the package.
Installation
This package supports Laravel 11, 12 and 13 and needs PHP 8.2 or higher (PHP 8.3+ is required when running on Laravel 13).
You can install the package via composer:
composer require aavinseth/laravel-translate
The free Google Translate translator works out of the box. To use the other translators, install their (optional) dependencies:
# Google Cloud Translate (simple API key based, V2 client) composer require google/cloud-translate:^1.18 # DeepL (requires a PSR-18 HTTP client such as Guzzle) composer require scn/deepl-api-connector:^4.0 guzzlehttp/guzzle:^7.8 php-http/discovery
Config
After installation publish the config file:
php artisan vendor:publish --provider="Aavinseth\LaravelTranslate\AutoTranslateServiceProvider"
You can specify your source language, the target language(s), the translator and the path to your language files in there.
Translators
| Name | Free | File | Documentation | Available languages |
|---|---|---|---|---|
| Google Translate HTTP | Yes | Aavinseth\LaravelTranslate\Translators\SimpleGoogleTranslator | / | Over 100 |
| Google Cloud Translate | No | Aavinseth\LaravelTranslate\Translators\GoogleCloudTranslator | Documentation | Over 100 |
| DeepL API v2 | No | Aavinseth\LaravelTranslate\Translators\DeeplTranslator | Documentation | EN, DE, FR, ES, PT, IT, NL, PL, RU |
If you have lots of translations to make I recommend Google Cloud Translate or DeepL. They are fast, reliable and you will not encounter any rate limiting.
Usage
Missing translations
Simply call the artisan missing command for translating all the translations that are set in your source language, but not in your target language:
php artisan autotrans:missing
E.g. you have English set as your source language. The source language has translations in auth.php:
<?php return [ 'failed' => 'These credentials do not match our records.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', ];
Your target language is German. The auth.php file has the following translations:
<?php return [ 'failed' => 'Diese Kombination aus Zugangsdaten wurde nicht in unserer Datenbank gefunden.', ];
The artisan missing command will then translate the missing auth.throttle key.
All translations
To overwrite all your existing target language keys with the translation of the source language simply call:
php artisan autotrans:all
This will overwrite every single key with a translation of the equivalent source language key.
Parameters
Sometimes you have translations like these:
'welcome' => 'Welcome, :name',
They can be replaced with variables. When we pass these placeholders to a translator service, weird things can happen. Sometimes the placeholder comes back in upper-case letters or it has been translated. Thankfully the package will respect your variable placeholders, so they will be the same after the translation.
Extending
You can create your own translator by creating a class that implements \Aavinseth\LaravelTranslate\Translators\TranslatorInterface. Simply reference it in your config file.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- Aavinseth
- Benjamin Bortels (original author)
- Mohamed Said (vendored
laravel-langmanManager) - All Contributors
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-10