Laravel package for multilingual field translations via polymorphic relations
afzaal565/field-translations is a Laravel package for laravel package for multilingual field translations via polymorphic relations.
It currently has 4 GitHub stars and 8 downloads on Packagist (latest version 1.0.0).
Install it with composer require afzaal565/field-translations.
Discover more Laravel packages by afzaal565
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package for managing field translations in your database tables using polymorphic relations.
You can install the package via composer:
composer require afzaal565/field-translations
Publish the configuration file:
php artisan vendor:publish --provider="FieldTranslations\Providers\FieldTranslationProvider"
This will create a field-translations.php config file in your config directory.
use FieldTranslations\Traits\HasTranslations;
class YourModel extends Model
{
use HasTranslations;
protected $translatable = [
'title',
'description',
// Add your translatable fields here
];
}
Run the migrations:
php artisan migrate
// Set translations
$model->setTranslation('title', 'en', 'English Title');
$model->setTranslation('title', 'es', 'Spanish Title');
// Get translations
$model->getTranslation('title', 'en'); // Returns: English Title
$model->getTranslation('title', 'es'); // Returns: Spanish Title
// Get all translations for a field
$model->getTranslations('title'); // Returns array of all translations
// Check if translation exists
$model->hasTranslation('title', 'en'); // Returns boolean
In your config/field-translations.php file, you can configure:
Please see CONTRIBUTING.md for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.