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
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
Roles and Permissions in Laravel 13
14 lessons
57 min
Queues in Laravel 13
18 lessons
1 h 12 min read