Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/reliqarts/laravel-auto-translator

Automatic translation for Laravel 10+
https://github.com/reliqarts/laravel-auto-translator

laravel locale localization translate translation

Last synced: 3 months ago
JSON representation

Automatic translation for Laravel 10+

Awesome Lists containing this project

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](https://laravel.com/docs/10.x/localization#using-translation-strings-as-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](https://laravel.com/docs/10.x/localization#using-translation-strings-as-keys))
- Easy to configure, with support for custom translator implementation

## Installation

Install via composer:

```bash
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](https://github.com/reliqarts/laravel-auto-translator/blob/main/config/config.php).

```bash
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

| Implementation | Paid | Documentation | Available languages |
|------------------------------------------------------------------------|------|----------------------------------------|---------------------|
| \ReliqArts\AutoTranslator\Service\Translator\SimpleGoogleApiTranslator | No | N/A | 100+ |
| \ReliqArts\AutoTranslator\Service\Translator\DeepLTranslator | Yes | [Docs](https://www.deepl.com/docs-api) | 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](https://github.com/Stichoza/google-translate-php).

## Usage

### Artisan Command

The package provides an easy-to-use command which you may run on-demand or on a schedule.

```bash
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.

```bash
php artisan auto-translator:translate es,de
```

An optional `replace-existing` flag (`r`) allows you to override existing translations.
e.g.

```bash
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 :smiley:

## Credits & Inspiration

This package was inspired by [laravel-auto-translate](https://github.com/ben182/laravel-auto-translate) and is made
possible by the following:

- [laravel-translatable-string-exporter](https://github.com/kkomelin/laravel-translatable-string-exporter)
by [kkomelin](https://github.com/kkomelin)
- [google-translate-php](https://github.com/Stichoza/google-translate-php) by [stichoza](https://github.com/Stichoza)
- [contributors](https://github.com/reliqarts/laravel-auto-translator/graphs/contributors)

---
All done! :beers: