Language update

Added different level of language preference functionaloty which can be
set from the new option in top navigation bar
Lanaguage preference can be set as
* System language (Default for all users)
* Session based   (User who are not logged in and want to see they
system in language of their choice can set their preference in browser
session)
* User lever (for authenticated users who have updated their language
preference, system will change into their selected language when they
log into the system)
This commit is contained in:
Manish Verma
2018-08-08 15:37:25 +05:30
parent 1013c89634
commit 3b76605892
11 changed files with 136 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ use Hash;
// classes
use Illuminate\Http\Request;
use Lang;
use Session;
/**
* GuestController.
@@ -415,4 +416,30 @@ class UnAuthController extends Controller
}
}
}
/**
* Function to chnage user language preference
*
* @param string $lang //desired language's iso code
*
* @category function to change system's language
*
* @return response
*/
public static function changeUserLanguage($lang)
{
$path = base_path('resources/lang'); // Path to check available language packages
if (array_key_exists($lang, \Config::get('languages')) && in_array($lang, scandir($path))) {
if (\Auth::check()) {
$id = \Auth::user()->id;
$user = User::find($id);
$user->user_language = $lang;
$user->save();
} else {
Session::put('language', $lang);
}
}
return redirect()->back();
}
}