Download the PHP package wecansync/laravel-translations without Composer
On this page you can find all versions of the php package wecansync/laravel-translations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wecansync/laravel-translations
More information about wecansync/laravel-translations
Files in wecansync/laravel-translations
Package laravel-translations
Short Description Manage translations in a seperated table
License MIT
Homepage https://github.com/wecansync/laravel-translations
Informations about the package laravel-translations
Laravel Translation Manager
Overview
Laravel Translation Management is a powerful, database-driven translation package that simplifies multi-language content management in Laravel applications. Store translations in dedicated database tables with automatic management through Eloquent events.
Features
- Database-Driven Translations: Store translations in dedicated tables for dynamic management
- Multi-Language Support: Handle unlimited languages with ease
- Automatic Translation Management: Translations are saved/updated automatically via Eloquent events
- Configurable Architecture: Customize foreign keys, owner keys, and column names per model
- Automatic Slug Generation: Generate unique slugs from translatable fields
- Locale Support: Automatically store language codes in translation records
- Route Skipping: Selectively disable auto-save on specific routes
- Performance Optimized: Built-in caching for language lookups
- Simple Integration: Just add a trait to your models
- Zero Dependencies: Only requires Laravel/Eloquent
Installation
Install the package via Composer:
Publish the configuration file:
This will create config/laravel-translations.php with default settings.
Quick Start
1. Create Database Tables
You need three types of tables:
Languages table:
Main model table (e.g., products):
Translation table (e.g., products_translations):
2. Set Up Your Models
Main Model (Product.php):
Translation Model (ProductTranslation.php):
3. Use in Your Application
Store with translations:
Retrieve translations:
Advanced Usage
Configuration Options
The $translation_model property accepts the following options:
Global Configuration
Edit config/laravel-translations.php:
Form Structure
Create forms with nested arrays using language IDs as keys:
Manual Translation Management
Use withTranslations() for batch operations or when routes are skipped:
Deleting Translations
API Methods
Use Cases
E-commerce Products
Blog Posts
Categories with Skip Routes
How It Works
- Automatic Saving: When you save a model, the
savedevent triggers translation management - Request Extraction: Translations are extracted from the request using the configured key
- Language Validation: Each language ID is validated against the languages table (cached)
- Slug Generation: If configured, unique slugs are generated from the specified field
- Locale Storage: If enabled, language codes are automatically stored
- Cascade Delete: When a model is deleted, all translations are removed
Performance
- Language Caching: Language lookups are cached in memory to reduce queries
- Bulk Operations: Use
withTranslations()for batch inserts/updates - Eager Loading: Load translations with
->with('translationRelation')
Example Application
Check the /example directory for a complete working Laravel application with:
- Categories (basic usage)
- Products (with slug generation)
- Posts (with SEO fields)
- Multiple languages
- CRUD operations
Requirements
- PHP >= 8.0
- Laravel >= 8.0
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository at https://github.com/EbrahimHanna580/translation-manager
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure:
- Code follows existing patterns and conventions
- Add tests for new features
- Update documentation as needed
Security
If you discover any security-related issues, please report them by emailing [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: [email protected]