Download the PHP package almoayad/laratrans without Composer
On this page you can find all versions of the php package almoayad/laratrans. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download almoayad/laratrans
More information about almoayad/laratrans
Files in almoayad/laratrans
Package laratrans
Short Description LaraTrans is a Laravel package that simplifies the process of handling translations for your models. It allows you to easily create, update, and delete translations for specific model properties, making your application ready for multilingual support with minimal effort.
License MIT
Informations about the package laratrans
LaraTrans
LaraTrans is a Laravel package that simplifies the process of handling translations for your models. It allows you to easily create, update, and delete translations for specific model properties, making your application ready for multilingual support with minimal effort.
Version 3.0 Updates
- Multiple Storage Strategies
- Single table mode (default)
- Dedicated tables mode for better organization and performance
- Migration System
- Easily switch between storage strategies
- Migrate existing translations between strategies
- Clean up unused translation tables
- Enhanced Validation
- Property-specific validation rules
- Required locales per property
- Unique translation validation
- Improved API
- Strategy-based architecture
- Better performance and reliability
- Extended translation methods
- Added support for Laravel 11
Requirements
- PHP 8.2 or higher
- Laravel 8.0 or higher (including Laravel 11)
Installation
You can install the package via Composer:
Next, publish the migration and configuration files:
Then, run the migration:
Configuration
After publishing the configuration file, you can customize various aspects of LaraTrans in config/laratrans.php
:
Usage
Step 1: Add the HasTranslations Trait
Add the HasTranslations trait to your model:
Step 2: Create Translations
You can create translations in several ways:
Step 3: Retrieve Translations
Step 4: Query with Translations
Storage Strategies
Single Table Mode (default)
All translations are stored in one table with polymorphic relationships.
- Good for applications with fewer models needing translation
- Simple setup and migration
- Uses the standard
laratrans_translations
table
Dedicated Tables Mode
Each model has its own translation table for better performance and organization.
- Better for applications with many translatable models
- Improved query performance
- Better database organization
- Creates tables like
trans_products_translations
,trans_categories_translations
, etc.
Switching Storage Strategies
Creating Dedicated Translation Tables
Validation
LaraTrans includes a robust validation system:
Global Validation Rules
Property-Specific Rules
Validation in Practice
Caching
LaraTrans includes a powerful caching system for improved performance. The TranslationCache trait provides automatic caching of translations with smart cache invalidation.
Setting Up Caching
-
Add the TranslationCache trait to your model (after HasTranslations):
- Configure caching options in
config/laratrans.php
:
Using Cached Translations
Cache Invalidation
The cache is automatically invalidated in the following scenarios:
- When setting new translations via
setTranslation()
- When deleting the model (all related translations are removed from cache)
- When the cache duration expires
- When bulk updating translations
Automatic Features
LaraTrans automatically:
- Validates translations based on your configuration
- Creates translations during model creation
- Updates translations during model updates
- Deletes translations when the model is deleted
- Falls back to the default locale when a translation is missing (configurable)
- Handles migrations between storage strategies
Customization
You can customize LaraTrans by:
- Extending the HasTranslations trait
- Modifying the configuration file
- Creating custom validation rules
- Adjusting the migration file
- Creating dedicated translation tables for specific models
Testing the Package Locally
-
Add to your Laravel application's
composer.json
: - Then run:
License
LaraTrans is open-source software licensed under the MIT license.
Feedback and Contributions
If you have any feedback or suggestions, feel free to open an issue or submit a pull request. Contributions are more than welcome!
Version History
- 3.0.0: Added storage strategies, migration system, enhanced validation, and Laravel 11 support
- 2.0.0: Added Laravel 11 support, validation system, and configuration options
- 1.0.4: Initial release with basic translation functionality
Developed with ❤️ by Mohamad Almoayad.
This package is maintained with pride by Mo Designs Studio.