GitHub - Astrotomic/laravel-translatable: A Laravel package for multilingual mod...
source link: https://github.com/Astrotomic/laravel-translatable
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
Introduction
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.
Installation
composer require astrotomic/laravel-translatable
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
- How To Add Multilingual Support to Eloquent
- How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application
- How to Add Multi-Language Models to Laravel QuickAdminPanel
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
Please see SECURITY for details.
Credits
Versions
Package Laravel PHP v11.4 - v11.55.6.* / 5.7.* / 5.8.* / 6.*
>=7.1.3
v11.0 - v11.3
5.6.* / 5.7.* / 5.8.*
>=7.1.3
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK