reliqarts/laravel-auto-translator

Automatic translations for Laravel.

v1.0.4 2024-07-15 21:26 UTC

This package is auto-updated.

Last update: 2024-11-15 22:24:56 UTC


README

Laravel Auto-Translator

Laravel Automatic Translator, for Laravel 10+

test Codecov Latest Stable Version License

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:

  1. Add the \ReliqArts\AutoTranslator\Http\Middleware\LanguageDetector middleware to the web route group in your App\Http\Kernel class.
  2. 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! 🍻