Download the PHP package rpwebdevelopment/laravel-ugc-translate without Composer
On this page you can find all versions of the php package rpwebdevelopment/laravel-ugc-translate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rpwebdevelopment/laravel-ugc-translate
More information about rpwebdevelopment/laravel-ugc-translate
Files in rpwebdevelopment/laravel-ugc-translate
Package laravel-ugc-translate
Short Description User generated content translation package
License MIT
Homepage https://github.com/rpwebdevelopment/laravel-ugc-translate
Informations about the package laravel-ugc-translate
User generated content translation package
This is a Laravel specific package designed to automate the translation of user generated content in a database driven fashion.
Installation
You can install the package via composer:
Configuration
This package offers you the option of using the free-to-use, zero configuration Google Translate package from Stichoza, or DeepL API, or Amazon 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:
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.
You can update the config file ugc-translate.php
in order to set any languages needed for translation:
Usage
The package provides a new trait that can be used in order to apply automatic translations:
In order to define translatable fields, and languages required for translation our models will now require a new
property $ugcTranslatable
defining the DB fields to be translated:
Unless you have disabled auto-translate, creating or updating a record within your model will cause translations
to be generated and stored. The package leverages Laravel's locale
in order to assert which language is to be
returned. If we take our posts model above with the following record:
You can achieve the following:
Sometimes you may wish to output a specific language value without switching the application locale, this can be achieved using the following method:
Sometimes you may not need all the default languages for every model, in order to override the default languages on
a model you can simply add the getUgcLanguagesAttribute
method to the model returning an array of locale codes:
If you use Livewire in your application there is a custom modal available for editing & locking specific translations, you can publish the modal component and view by runningg the following command:
Once published you can add the modal into your project with the following tag:
This will add a button to your blade template that will open the following modal:
Locking translations will prevent them from being automatically updated.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-ugc-translate with dependencies
aws/aws-sdk-php-laravel Version ^3.10
deeplcom/deepl-php Version ^1.1
spatie/laravel-package-tools Version ^1.13.0
stichoza/google-translate-php Version ^5.2