jobmetric / laravel-translation
This is a package for translating the contents of different Laravel projects.
Requires
- php: >=8.0.1
- ext-json: *
- jobmetric/laravel-custom-field: ^1.7
- jobmetric/laravel-language: ^1.8
- jobmetric/laravel-metadata: ^2.2
- jobmetric/laravel-package-core: ^1.18.5
- laravel/framework: >=9.19
This package is auto-updated.
Last update: 2025-08-29 17:28:51 UTC
README
Translation for Laravel
Laravel-Translation is a powerful package that simplifies the management of multilingual content within Laravel applications. It offers dynamic translation storage, retrieval, and updates, seamlessly integrating with your models through the HasTranslation trait. The core features include:
Package:
jobmetric/laravel-translation
PHP: 8.1+ (8.2+ recommended) · Laravel: 9/10/11
Provider:JobMetric\Translation\TranslationServiceProvider
Highlights
🔧 Custom Validation: Ensures translation data integrity with flexible rules and error handling.
🌟 Model Integration: Supports multi-language attributes with versioning, soft deletes, and event-driven updates.
🗃️ API Resources: Provides structured serialization for translation data, facilitating API responses.
⚙️ Extensible Architecture: Includes custom exceptions, event handling, and dynamic translation management for scalable localization.
🔍 Query Support: Enables scope queries and relationship management for efficient multilingual data handling.
🗣️ Language Files: Centralized language files for consistent, maintainable multilingual user communication.
Install via composer
Run the following command to pull in the latest version:
composer require jobmetric/laravel-translation
Documentation
Undergoing continuous enhancements, this package evolves each day, integrating an array of diverse features. It stands as an indispensable asset for enthusiasts of Laravel, offering a seamless way to harmonize their projects with translation database models.
In this package, you can employ it seamlessly with any model requiring database translation.
Now, let's delve into the core functionality.
Before doing anything, you must migrate after installing the package by composer.
php artisan migrate
Meet the HasTranslation
class, meticulously designed for integration into your model. This class automates essential tasks, ensuring a streamlined process for:
In the first step, you need to connect this class to your main model.
Quickstart
use Illuminate\Database\Eloquent\Model; use JobMetric\Translation\HasTranslation; class Post extends Model { use HasTranslation; /** * @var array<int, string> */ protected array $translatables = ['title', 'summary', 'body']; /** * @var bool */ protected bool $translationVersioning = true; } // Create & attach translations $post = Post::create(['status' => 'published']); $post->translate('en', ['title' => 'Hello', 'body' => 'Welcome']); $post->translate('fa', ['title' => 'سلام', 'body' => 'خوش آمدید']); OR $post = Post::create([ 'status' => 'published' 'translations' => [ 'en' => ['title' => 'Hello', 'body' => 'Welcome'], 'fa' => ['title' => 'سلام', 'body' => 'خوش آمدید'], ], ]); // Read $title = $post->getTranslation('title', 'fa'); // 'سلام'
👉 Dive deeper in /docs:
- Main Trait - HasTranslation
- Rule TranslationFieldExist
- Events
- Resource - TranslationCollection
- Resource - Translation
- Request - MultiTranslationArray
- Request - MultiTranslationTypeObject
- Request - TranslationArray
- Request - TranslationTypeObject
Contributing
Thank you for considering contributing to the Laravel Translation! The contribution guide can be found in the CONTRIBUTING.md.
License
The MIT License (MIT). Please see License File for more information.