-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Need more lang files translated - Closes #25
- Loading branch information
HDVinnie
committed
Dec 28, 2017
1 parent
961ffa8
commit e1934a2
Showing
41 changed files
with
682 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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 | ||
*/ | ||
|
||
if (!function_exists('language')) { | ||
/** | ||
* Get the language instance. | ||
* | ||
* @return App\Language | ||
*/ | ||
function language() | ||
{ | ||
return app('language'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?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\Middleware; | ||
|
||
use App; | ||
use Auth; | ||
use Closure; | ||
|
||
use App\Language; | ||
|
||
use Carbon\Carbon; | ||
|
||
class SetLanguage | ||
{ | ||
/** | ||
* This function checks if language to set is an allowed lang of config. | ||
* | ||
* @param string $locale | ||
**/ | ||
private function setLocale($locale) | ||
{ | ||
// Check if is allowed and set default locale if not | ||
if (!Language::allowed($locale)) { | ||
$locale = config('app.locale'); | ||
} | ||
|
||
// Set app language | ||
App::setLocale($locale); | ||
|
||
// Set carbon language | ||
if (config('language.carbon')) { | ||
// Carbon uses only language code | ||
if (config('language.mode.code') == 'long') { | ||
$locale = explode('-', $locale)[0]; | ||
} | ||
|
||
Carbon::setLocale($locale); | ||
} | ||
|
||
// Set date language | ||
if (config('language.date')) { | ||
// Date uses only language code | ||
if (config('language.mode.code') == 'long') { | ||
$locale = explode('-', $locale)[0]; | ||
} | ||
|
||
\Date::setLocale($locale); | ||
} | ||
} | ||
|
||
public function setDefaultLocale() | ||
{ | ||
$this->setLocale(config('app.locale')); | ||
} | ||
|
||
public function setUserLocale() | ||
{ | ||
$user = Auth::user(); | ||
|
||
if ($user->locale) { | ||
$this->setLocale($user->locale); | ||
} else { | ||
$this->setDefaultLocale(); | ||
} | ||
} | ||
|
||
public function setSystemLocale($request) | ||
{ | ||
if ($request->session()->has('locale')) { | ||
$this->setLocale(session('locale')); | ||
} else { | ||
$this->setDefaultLocale(); | ||
} | ||
} | ||
|
||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
if (Auth::check()) { | ||
$this->setUserLocale(); | ||
} else { | ||
$this->setSystemLocale($request); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
Oops, something went wrong.