mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-05-03 08:50:22 -05:00
(Feature) User Language System
- Need more lang files translated - Closes #25
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D
|
||||
* @license https://choosealicense.com/licenses/gpl-3.0/ GNU General Public License v3.0
|
||||
* @author HDVinnie
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Auth;
|
||||
|
||||
use App\Language;
|
||||
|
||||
class LanguageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Set locale if it's allowed.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param \Illuminate\Http\Request $request
|
||||
**/
|
||||
private function setLocale($locale, $request)
|
||||
{
|
||||
// Check if is allowed and set default locale if not
|
||||
if (!Language::allowed($locale)) {
|
||||
$locale = config('app.locale');
|
||||
}
|
||||
|
||||
if (Auth::check()) {
|
||||
Auth::user()->setAttribute('locale', $locale)->save();
|
||||
} else {
|
||||
$request->session()->put('locale', $locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set locale and return home url.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
public function home($locale, Request $request)
|
||||
{
|
||||
$this->setLocale($locale, $request);
|
||||
|
||||
return redirect(url('/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set locale and return back.
|
||||
*
|
||||
* @param string $locale
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
public function back($locale, Request $request)
|
||||
{
|
||||
$this->setLocale($locale, $request);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user