reliqarts / laravel-auto-translator
Automatic translations for Laravel.
Fund package maintenance!
reliq
Requires
- php: ^8.2
- deeplcom/deepl-php: ^1.5
- illuminate/support: ^8.0|^9.0|^10|^11.0
- kkomelin/laravel-translatable-string-exporter: ^1.21
- reliqarts/laravel-common: ^7.0|^8.0
- stichoza/google-translate-php: ^5.1
Requires (Dev)
- laravel/pint: ^1.13
- orchestra/testbench: ^8.12|^9.2
- phpro/grumphp: ^2.0
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.6|^11.0
- yieldstudio/grumphp-laravel-pint: ^1.0
README
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.
Features
- Simple, easy to schedule artisan command to generate all translations
- Automatic language file generation (json)
- Easy to configure, with support for custom translator implementation
Installation
Install via composer:
composer require reliqarts/laravel-auto-translator
Configuration
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"
Translator
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.
Built-in Implementations
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.
Usage
Artisan Command
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
Language Switcher Endpoint and Middleware
The package provides a route/middleware combination which allows users to switch the language of your application.
Usage:
- 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 😃
Credits & Inspiration
This package was inspired by laravel-auto-translate and is made possible by the following:
All done! 🍻