Skip to main content
Back to packages
841 GitHub stars

spatie/laravel-translation-loader

View on GitHub

Description

Store your translations in the database or other sources

You can create a translation in the database by creating and saving an instance of the Spatie\TranslationLoader\LanguageLine-model:

use Spatie\TranslationLoader\LanguageLine;
 
LanguageLine::create([
'group' => 'validation',
'key' => 'required',
'text' => ['en' => 'This is a required field', 'nl' => 'Dit is een verplicht veld'],
]);

You can fetch the translation with Laravel's default __ function:

__('validation.required'); // returns 'This is a required field'
 
app()->setLocale('nl');
 
__('validation.required'); // returns 'Dit is een verplicht veld'

You can still keep using the default language files as well. If a requested translation is present in both the database and the language files, the database version will be returned.

If you need to store/override JSON translation lines, just create a normal LanguageLine with group => '*'.

Recent Courses on Laravel Daily

Next.js Basics for Laravel Developers

11 lessons
58 min

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.