Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Laravel Translatable

astrotomic/laravel-translatable image

Laravel Translatable stats

Downloads
3.5M
Stars
1,117
Open Issues
15
Forks
137

View on GitHub →

A Laravel package for multilingual models

Laravel Translatable Package by Astrotomic

The Laravel Translatable package by Astrotomic provides an efficient way to handle multilingual models in Laravel applications. This package simplifies the management of translations by storing and retrieving them directly from the database associated with model instances.

Key Features

  • Ease of Use: Directly interact with translations through model properties without the need for additional code.
  • Flexible Retrieval: Fetch translations using simple method calls or by setting the application locale.
  • Efficient Storage: Save translations directly into the database with minimal overhead.
  • Multiple Translations: Easily handle multiple translations for a model during creation or update operations.

Installation

Install the package via Composer:

composer require astrotomic/laravel-translatable

Usage Examples

Retrieving Translations

$post = Post::first();
echo $post->translate('en')->title; // Outputs the title in English
 
App::setLocale('en');
echo $post->title; // Automatically fetches the English title

Saving Translations

$post = Post::first();
$post->translate('en')->title = 'Updated Title';
$post->save(); // Saves the updated English title

Handling Multiple Translations at Once

$data = [
'author' => 'Author Name',
'en' => ['title' => 'English Title'],
'fr' => ['title' => 'French Title'],
];
$post = Post::create($data);
echo $post->translate('fr')->title; // Outputs the French title

Support and Contribution

Developers are encouraged to contribute to the repository by following the guidelines provided in the CONTRIBUTING and CODE OF CONDUCT sections. For security issues, refer to the SECURITY document.

Treeware License

You are encouraged to contribute to the Treeware initiative if you use this package in your production environment. By helping with tree planting efforts, you support climate action and community building.

Further Learning

  • Detailed documentation is available on the GitBook.
  • Additional tutorials and guides can be found on Laravel News and other community blogs which provide insights on using this package effectively.

This package is maintained by Tom Witkowski and was originally authored by Dimitrios Savvopoulos, with significant contributions from the community and support for various Laravel and PHP versions.

Astrotomic photo

We want to provide helpful, solid and easy to use open source packages. Most of them will be for Laravel - but sometimes also plain PHP.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Astrotomic Laravel Translatable Related Articles

Translatable Enums image

Translatable Enums

Read article
Build Your SaaS In Days With SaaSykit image

Build Your SaaS In Days With SaaSykit

Read article
Create Beautiful Admin Panels in Laravel image

Create Beautiful Admin Panels in Laravel

Read article
Manage any Laravel app as if it was a CMS image

Manage any Laravel app as if it was a CMS

Read article
Filament TALL Stack Admin Panel v2 Released image

Filament TALL Stack Admin Panel v2 Released

Read article
Squire: Static Eloquent Model Library image

Squire: Static Eloquent Model Library

Read article
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search