Updated: Enable/Disable dynamic localization. Dropdown to change language for users
This commit is contained in:
parent
9943fb28dd
commit
130b4cda04
|
@ -5,8 +5,10 @@ APP_DEBUG=false
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
#list with timezones https://www.php.net/manual/en/timezones.php
|
#list with timezones https://www.php.net/manual/en/timezones.php
|
||||||
APP_TIMEZONE=UTC
|
APP_TIMEZONE=UTC
|
||||||
# Language is chosen automatically depending on the users browserlanguage.
|
|
||||||
# It will default to this value, if the translation is not available. Best would be to keep this "en"
|
# If set to true, Language is chosen automatically depending on the users browserlanguage.
|
||||||
|
DYNAMIC_LOCALE = false
|
||||||
|
# The language of the Dashboard. This is also the fallback if dynamic_locale is true but no translation is found
|
||||||
LOCALE=en
|
LOCALE=en
|
||||||
# You can grab the Language-Codes for the Datatables from this Website https://datatables.net/plug-ins/i18n/
|
# You can grab the Language-Codes for the Datatables from this Website https://datatables.net/plug-ins/i18n/
|
||||||
DATATABLE_LOCALE=en-gb
|
DATATABLE_LOCALE=en-gb
|
||||||
|
|
|
@ -19,15 +19,17 @@ class SetLocale
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
if (Session::has('locale')) {
|
if (Session::has('locale')) {
|
||||||
$locale = Session::get('locale', config('app.locale'));
|
$locale = Session::get('locale', config('app.locale'));
|
||||||
} else {
|
} else {
|
||||||
$locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
|
if (config('app.dynamic_locale')) {
|
||||||
|
$locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
|
||||||
|
|
||||||
if (!in_array($locale, config('app.available_locales'))) {
|
if (!in_array($locale, config('app.available_locales'))) {
|
||||||
$locale = config('app.locale');
|
$locale = config('app.locale');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
App::setLocale($locale);
|
App::setLocale($locale);
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,17 @@ return [
|
||||||
|
|
||||||
'timezone' => env('APP_TIMEZONE', 'UTC'),
|
'timezone' => env('APP_TIMEZONE', 'UTC'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Dyamic Locales
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Change the Locale depending on the Users Browserlanguage
|
||||||
|
| Can either be true or false
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'dynamic_locale' => env('DYNAMIC_LOCALE', 'false'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Application Locale Configuration
|
| Application Locale Configuration
|
||||||
|
@ -82,7 +93,18 @@ return [
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'locale' => env('LOCALE', 'en'),
|
'locale' => env('LOCALE', 'en'),
|
||||||
'available_locales' => array('en', 'de', 'it', 'zh'),
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Available Locales
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You should not change this
|
||||||
|
| If the dashboard is 100% translated in a certain language, it will be added here
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'available_locales' => array('English'=>'en','German'=>'de','Italian'=>'it','Chinese'=>'zh'),
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -50,11 +50,9 @@
|
||||||
<form method="post" action="{{route('changeLocale')}}">
|
<form method="post" action="{{route('changeLocale')}}">
|
||||||
@csrf
|
@csrf
|
||||||
<select class="dropdown-item" id="inputLocale" name="inputLocale" onchange="this.form.submit()">
|
<select class="dropdown-item" id="inputLocale" name="inputLocale" onchange="this.form.submit()">
|
||||||
<option value="de">DE</option>
|
@foreach (config("app.available_locales") as $key=>$value)
|
||||||
<option value="it">IT</option>
|
<option @if(Session::get("locale") == $value) selected="selected" @endif value="{{$value}}">{{$key}}</option>
|
||||||
<option value="en">EN</option>
|
@endforeach
|
||||||
<option value="zh">ZH</option>
|
|
||||||
<option value="fr">FR</option>
|
|
||||||
</select>
|
</select>
|
||||||
</form>
|
</form>
|
||||||
<!-- End Language Selection -->
|
<!-- End Language Selection -->
|
||||||
|
|
Loading…
Reference in a new issue