afzaal565 / field-translations
Laravel package for multilingual field translations via polymorphic relations
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/afzaal565/field-translations
This package is auto-updated.
Last update: 2025-09-17 14:36:59 UTC
README
A Laravel package for managing field translations in your database tables using polymorphic relations.
Installation
You can install the package via composer:
composer require afzaal565/field-translations
Configuration
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.
Usage
1. Add the Trait to Your Model
use FieldTranslations\Traits\HasTranslations; class YourModel extends Model { use HasTranslations; protected $translatable = [ 'title', 'description', // Add your translatable fields here ]; }
2. Create Translation Tables
Run the migrations:
php artisan migrate
3. Working with Translations
// 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
Features
- Easy to integrate with any Laravel model
- Support for multiple languages
- Automatic translation table creation
- Flexible configuration options
- Cache support for better performance
Configuration Options
In your config/field-translations.php
file, you can configure:
- Default language
- Available languages
- Cache settings
- Table naming conventions
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security related issues, please email afzaalhussain565@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.