Astrotomic / laravel-translatable by Gummibeer

A Laravel package for multilingual models
4,293,511
1,191
21
Package Data
Maintainer Username: Gummibeer
Maintainer Contact: gummibeer@astrotomic.info (Tom Witkowski)
Package Create Date: 2019-06-17
Package Last Update: 2024-04-17
Home Page: https://docs.astrotomic.info/laravel-translatable/
Language: PHP
License: MIT
Last Refreshed: 2024-04-22 15:00:21
Package Statistics
Total Downloads: 4,293,511
Monthly Downloads: 111,001
Daily Downloads: 4,929
Total Stars: 1,191
Total Watchers: 21
Total Forks: 148
Total Open Issues: 19

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 |