astrotomic/laravel-translatable
Laravel package for translatable Eloquent models. Store model translations in the database and automatically fetch/save multilingual attributes based on locale, reducing boilerplate when working with multi-language content.
Strengths:
Translatable), making it easy to adopt for existing models.translateOrDefault) ensure graceful degradation when translations are missing, improving UX resilience.locales, translations_wrapper) allows alignment with project-specific conventions (e.g., locale codes like "eng" instead of "en").Weaknesses:
post_translations), which may impact write performance and storage costs at scale.Laravel Ecosystem Compatibility:
Resource::collection() can serialize translations automatically).Migration Path:
Translatable trait.Critical Risks:
Validator).withTranslations() relation or loadMissing() methods.Moderate Risks:
README or custom config.Low Risks:
translate('fr')->title), and the GitBook docs provide clear examples.MediaLibrary, Cashier).['en', 'fr']) or dynamic (user-selected)? Dynamic locales may require runtime validation.en regardless of user locale)?title length limits).Core Stack:
App::setLocale()) without reinventing them.$post->translate(locale: 'fr', withFallback: true);
Extended Stack:
getTranslationsArray().Phase 1: Proof of Concept (PoC)
BlogPost, ProductDescription).composer require astrotomic/laravel-translatable.php artisan vendor:publish --tag=translatable.post_translations).Translatable trait to the model and define $translatedAttributes.Phase 2: Incremental Rollout
translate('es')->name).@lang directive or frontend i18n libraries).Accept-Language header).Phase 3: Optimization
(post_id, locale)).withTranslations() to eager-load translations in collections.How can I help you explore Laravel packages today?