A Laravel Eloquent trait to store model translations as JSON without extra database tables.
Spatie Laravel Translatable is a PHP package that provides a trait to make Eloquent models translatable. It allows developers to store and manage multilingual content directly in JSON columns within the model's database table, eliminating the need for separate translation tables. This simplifies the database schema while providing full locale-aware retrieval and querying capabilities.
Laravel developers building multilingual applications who need to store and manage translated content for Eloquent models efficiently. It's particularly useful for projects requiring content localization without complex database structures.
Developers choose this package because it offers a minimal, elegant solution that leverages Laravel's built-in JSON column support, reducing database complexity while providing powerful translation features. Its simple trait-based approach and comprehensive query scopes make it easier to implement than maintaining separate translation tables.
Making Eloquent models translatable
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Stores translations directly in JSON columns within the model's table, eliminating the need for separate translation tables and simplifying the database schema, as emphasized in the README's 'no extra table' approach.
Simply use the HasTranslations trait and define translatable attributes to enable multilingual support, making it quick to implement without extensive configuration or boilerplate code.
Provides built-in methods like whereLocale and whereJsonContainsLocale for locale-specific queries, allowing efficient filtering of translated records without writing custom SQL.
Supports translating nested keys within JSON columns using dot notation (e.g., meta->description), enabling localization of complex data structures as demonstrated in the README examples.
Relies on database JSON column support, which may not be available in all environments (e.g., older database versions) and can lead to vendor lock-in or migration challenges.
Focuses solely on backend storage and retrieval without built-in features for translation editing, validation, or admin interfaces, requiring additional development effort for full CMS integration.
Complex queries on JSON data, especially with multiple locales or nested structures, might suffer from slower performance compared to normalized table approaches, as JSON indexing can be less efficient.