Skip to main content
Back to packages
849 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 => '*'.