PHPackages                             rpwebdevelopment/laravel-ugc-translate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. rpwebdevelopment/laravel-ugc-translate

ActiveLibrary[Localization &amp; i18n](/categories/localization)

rpwebdevelopment/laravel-ugc-translate
======================================

User generated content translation package

0.3.0(1y ago)119MITPHPPHP ^8.1CI passing

Since May 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rpwebdevelopment/laravel-ugc-translate)[ Packagist](https://packagist.org/packages/rpwebdevelopment/laravel-ugc-translate)[ Docs](https://github.com/rpwebdevelopment/laravel-ugc-translate)[ RSS](/packages/rpwebdevelopment-laravel-ugc-translate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (10)Versions (10)Used By (0)

User generated content translation package
==========================================

[](#user-generated-content-translation-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9cb5c80e6640ae4c5954388676a774534a9a9db7228f7103efad5a8141eea71a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7270776562646576656c6f706d656e742f6c61726176656c2d7567632d7472616e736c6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rpwebdevelopment/laravel-ugc-translate)[![Packagist Downloads](https://camo.githubusercontent.com/5097f885b59f0a1b3976cdf95888edc09c783beb276a9b9119392dcd73ba1528/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7270776562646576656c6f706d656e742f6c61726176656c2d7567632d7472616e736c6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rpwebdevelopment/laravel-ugc-translate)[![License: MIT](https://camo.githubusercontent.com/31d2950fb64a30a3494ce524a78f3a1f6eabc9726c88fafc7e80925d661bd10b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c756576696f6c65742e7376673f7374796c653d666c61742d737175617265)](https://github.com/DeepLcom/deepl-php/blob/main/LICENSE)

This is a Laravel specific package designed to automate the translation of user generated content in a database driven fashion.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require rpwebdevelopment/laravel-ugc-translate

php artisan vendor:publish --tag="ugc-translate-migrations"
php artisan migrate

php artisan vendor:publish --tag="ugc-translate-config"
```

Configuration
-------------

[](#configuration)

This package offers you the option of using the free-to-use, zero configuration [Google Translate](https://github.com/Stichoza/google-translate-php) package from [Stichoza](https://github.com/Stichoza), or [DeepL API](https://github.com/DeepLcom/deepl-php), or [Amazon Translate](https://aws.amazon.com/translate/).

If leveraging the DeepL API you will need to add a valid `DEEPL_AUTH_TOKEN` to your `.env`.

If leveraging the Amazon Translate API you will need to ensure you have valid `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_DEFAULT_REGION` values set in your `.env`.

If you do not wish every record update/creation to trigger automatic translation, you can disable the observer by adding the following to your `.env` file:

```
UGC_AUTO_TRANSLATE_DISABLED=true
```

Sometimes you may only want translations enabled on a model if certain conditions are met, for example if a flag is set against the model instance, in order to achieve this you can add the method `getHasTranslationsAttribute` to the model returning a boolean value, i.e.

```
    public function getHasTranslationsAttribute(): bool
    {
        // your code here - returning bool
    }
```

You can update the config file `ugc-translate.php` in order to set any languages needed for translation:

```
    'translation-languages' => [
        'en-GB',
        'fr',
        'it',
        'de',
    ],
```

Usage
-----

[](#usage)

The package provides a new trait that can be used in order to apply automatic translations:

```
