Laravel Automatic Translator, for Laravel 10+
This package will scan your application, locate all translation string keys throughout and generate translations based on your configuration.
- Simple, easy to schedule artisan command to generate all translations
- Automatic language file generation (json)
- Easy to configure, with support for custom translator implementation
Install via composer:
composer require reliqarts/laravel-auto-translator
You may publish the configuration file and customize as you wish. Each built-in translator implementation has its own set of config options. All configuration options are explained in the configuration file.
php artisan vendor:publish --provider="\ReliqArts\AutoTranslator\ServiceProvider"
The auto_translate_via
key allows you to specify which translator should be used for automatic translations.
By default, this is set to Google's simple translator. Any service implementing the
\ReliqArts\AutoTranslator\Contract\Translator
interface may be used here.
Implementation | Paid | Documentation | Available languages |
---|---|---|---|
\ReliqArts\AutoTranslator\Service\Translator\SimpleGoogleApiTranslator | No | N/A | 100+ |
\ReliqArts\AutoTranslator\Service\Translator\DeepLTranslator | Yes | Docs | 30+ |
Important
For production use cases please consider using a paid translator service. Do not depend on the free Google HTTP implementation shipped with this package as it may break at any time. See original disclaimer on google-translate-php.
The package provides an easy-to-use command which you may run on-demand or on a schedule.
php artisan auto-translator:translate
You may pass one or more language codes (comma separated) in order to specify which languages should be translated to. e.g.
php artisan auto-translator:translate es,de
An optional replace-existing
flag (r
) allows you to override existing translations.
e.g.
php artisan auto-translator:translate es,de -r
The package provides a route/middleware combination which allows users to switch the language of your application.
- Add the
\ReliqArts\AutoTranslator\Http\Middleware\LanguageDetector
middleware to the web route group in yourApp\Http\Kernel
class. - Switch the language by sending a post request to the
switch-language
route. (name and endpoint changeable in config file) You may use a select box, set of flags, etc. to make calls to this endpoint. UI choice is totally yours 😃
This package was inspired by laravel-auto-translate and is made possible by the following:
All done! 🍻