Astrotomic / laravel-translatable by Gummibeer

A Laravel package for multilingual models
5,202,960
1,246
20
Package Data
Maintainer Username: Gummibeer
Maintainer Contact: gummibeer@astrotomic.info (Tom Witkowski)
Package Create Date: 2019-06-17
Package Last Update: 2024-10-07
Home Page: https://docs.astrotomic.info/laravel-translatable/
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:04:06
Package Statistics
Total Downloads: 5,202,960
Monthly Downloads: 136,232
Daily Downloads: 6,283
Total Stars: 1,246
Total Watchers: 20
Total Forks: 157
Total Open Issues: 27

Introduction

Total Downloads CircleCI StyleCI ScrutinizerCI Code Climate Code Coverage Latest Version MIT License GitBook

Laravel Translatable

If you want to store translations of your models into the database, this package is for you.

This is a Laravel package for translatable models. Its goal is to remove the complexity in retrieving and storing multilingual model instances. With this package you write less code, as the translations are being fetched/saved when you fetch/save your instance.

The full documentation can be found at GitBook.

Quick Example

Getting translated attributes

$post = Post::first();
echo $post->translate('en')->title; // My first post

App::setLocale('en');
echo $post->title; // My first post

App::setLocale('de');
echo $post->title; // Mein erster Post

Saving translated attributes

$post = Post::first();
echo $post->translate('en')->title; // My first post

$post->translate('en')->title = 'My cool post';
$post->save();

$post = Post::first();
echo $post->translate('en')->title; // My cool post

Filling multiple translations

$data = [
  'author' => 'Gummibeer',
  'en' => ['title' => 'My first post'],
  'fr' => ['title' => 'Mon premier post'],
];
$post = Post::create($data);

echo $post->translate('fr')->title; // Mon premier post

Tutorials

Add-Ons

Thanks to the community a few packages have been written using this package:

If you want to be add yours to this list, just open a PR.

Versions

| Package | Laravel | PHP | | :--- | :--- | :--- | | v11.1 | 5.6.* \| 5.7.* \| 5.8.* | >=7.1.3 | | v11.0 | 5.6.* \| 5.7.* \| 5.8.* | >=7.1.3 |