How spatie/laravel-translatable works
Project Type and Purpose
This is a Laravel package that provides a trait for making Eloquent models translatable, storing translations as JSON in the database without requiring additional tables.
Main Components
a. Core Components:
• HasTranslations Trait
• Translatable Service Provider
• Events System
• Model Integration Layer
• Database Layer
b. Supporting Components:
• Exception Handling
• Facade Layer
Application Layer (Top)
• How a Laravel application integrates with the package
• Example Eloquent model using the HasTranslations trait
Package Core (Middle)
• HasTranslations Trait (central component)
• TranslatableServiceProvider (initialization and configuration)
• Translatable Facade (public interface)
Implementation Layer (Bottom)
• JSON Storage in Database
• Event System
• Exception Handling
Specific Elements
Use the following visual elements:
• Rounded rectangles for traits and interfaces
• Blue: Core components (HasTranslations, TranslatableServiceProvider)
• Green: Public interfaces (Facade)
• Yellow: Event system
• Red: Exception handling
• Gray: Database storage
Component Relationships
Key interactions:
Laravel Application
• ↓
Eloquent Model with HasTranslations Trait
• ↓
TranslatableServiceProvider
• ↓
JSON Storage in Database
With side connections to:
• Events System (TranslationHasBeenSetEvent)
• Exception Handling (AttributeIsNotTranslatable)
Important Details to Highlight
• JSON storage mechanism (show how translations are stored in a single column)
• Locale handling and fallback system
• Query builder integration (whereLocale, whereLocales methods)
• Event dispatching system