Store your translations in the database with Laravel translation loader package
Store your translations in the database with Laravel translation loader package
In this article, you will be learning how to store your language data into database and translate in the laravel application.
Step 1: install Laravel translation loader through Composer:
Step 2: Open your config/app.php and replace Laravel’s translation service provider ( 'providers' ) :
From this :
To this:
If you don't find Illuminate\Translation\TranslationServiceProvider::class then add this spatie translation service prodivder as given above,
Step 3: Let's Publish Laravel translation loader migration file
it will create a new table called language_lines in the database which will hold your application translations:
Step 4: Publish the config file using this command
Step 5: Now migrate the language_lines table
Now, the setup & installation is completed guys. Let's add / insert the language translation into database in laravel
Example 1:
1. We are inserting the validation translation in different language vie Laravel Spatie Language Translation Model as given below:
2. You can fetch the translation with Laravel's default trans function:
Note: You have to add all the Laravel validation translation to work as I shown above in Example 1 - point 1.
also you can publish the laravel default language translation files as follows:
3. Change the Language with the following function.
Example 2:
1. If you need to store/override json translation lines, just create a normal LanguageLine with group => '*'.
2. You can fetch the translation with Laravel's default trans function:
That's it guys, I hope this helped you.