iam trying to make multilanguage view in laravel i set up everything but when i change the localization in config/app.php from "en" to "ar" ... it stays "en" and i tested with the function App::getLocal
my files of translation "messages.php" for "en"
'''
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/
"offer name required" => "the name field is required",
"offer name max" => "the name cannot exceed 100 characters",
"offer name unique" => "offer name is already used",
"offer photo required" => "photo field is required also"
];
''' for "ar"
'''
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/
"offer name required" => "يجب ادخال اسم العرض",
"offer name max" => "يجب أن لا يتعدى الاسم 100 عنصرا",
"offer name unique" => "هذا الاسم غير متوفر",
"offer photo required" => "يجب ادخال رابط الصورة"
];
''' when i print a message for test using this code : '''
<?php
namespace App\Http\Controllers;
use App;
use Illuminate\Http\Request;
class locale extends Controller
{
function getlocal(){
echo __('messages.offer name required');
echo(' <br> ');
}}
'''
it always prints in english eventhough iam putting it locale="ar" in app.php
i hope you can help me solve this .. and if you need any additional infos tell me .. thank you for your time
I would suggest to store the language in session and use a middleware to setLocale.
Working example
SetLocale.php middleware
Controller function to set a language
So now on everything that happens on the website, the middleware will check the language and set it to what's in session.
Also don't forget to specify the middleware in $middlewareGroups in app\Http\Kernel.php
You can create a form anywhere on website for the user to choose his language preference with a route to the controller function.