Package

Astrotomic Laravel Translatable

A Laravel package for multilingual models

Package

astrotomic/laravel-translatable

View on GitHub →

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 Laravel Translatable Related Articles

Translatable Enums image

Translatable Enums

Read article
How To Add Multilingual Support to Eloquent image

How To Add Multilingual Support to Eloquent

Read article
Laravel 5.7.16 Released image

Laravel 5.7.16 Released

Read article
Customizable Paginated Routes image

Customizable Paginated Routes

Read article
Laravel 5.6.9 Released image

Laravel 5.6.9 Released

Read article
Laravel 9.10 Released image

Laravel 9.10 Released

Read article

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

PhpStorm

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

PhpStorm

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Shift

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

Shift

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing