diff --git a/app/Classes/Settings/LanguageSettingsC.php b/app/Classes/Settings/LanguageSettingsC.php new file mode 100644 index 00000000..51a84300 --- /dev/null +++ b/app/Classes/Settings/LanguageSettingsC.php @@ -0,0 +1,41 @@ + REQUEST-VALUE (coming from the html-form) + "SETTINGS::LOCALE:DEFAULT" => "defaultLanguage", + "SETTINGS::LOCALE:DYNAMIC" => "autotranslate", + "SETTINGS::LOCALE:CLIENTS_CAN_CHANGE" => "canClientChangeLanguage", + "SETTINGS::LOCALE:AVAILABLE" => "languages", + "SETTINGS::LOCALE:DATATABLES" => "datatable-language" + ]; + + foreach($values as $key=>$value){ + Settings::where('key', $key)->update(['value' => $request->get($value)]); + Cache::forget("setting" .':'. $key); + } + + + return redirect()->route('admin.settings.index')->with('success', 'Language settings updated!'); + } + +} diff --git a/app/Http/Middleware/SetLocale.php b/app/Http/Middleware/SetLocale.php index c87e891d..a6937330 100644 --- a/app/Http/Middleware/SetLocale.php +++ b/app/Http/Middleware/SetLocale.php @@ -2,6 +2,7 @@ namespace App\Http\Middleware; +use App\Models\Settings; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; @@ -208,18 +209,17 @@ class SetLocale */ public function handle($request, Closure $next) { - if (Session::has('locale')) { - $locale = Session::get('locale', config('app.locale')); + $locale = Session::get('locale', Settings::getValueByKey("SETTINGS::LOCALE:DEFAULT")); } else { - if (!config('app.dynamic_locale')) { - $locale = config('app.locale'); + if (Settings::getValueByKey("SETTINGS::LOCALE:DYNAMIC") == "false") { + $locale = Settings::getValueByKey("SETTINGS::LOCALE:DEFAULT"); }else{ $locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2); - if (!in_array($locale, config('app.available_locales')) - || in_array(strtolower($this->getLocaleCodeForDisplayLanguage($locale)), UNSUPPORTED_LANGS)) { - $locale = config('app.locale'); + if (!in_array($locale, array_flip(preg_split ("/\,/", Settings::getValueByKey("SETTINGS::LOCALE:AVAILABLE")))) + || !in_array(strtolower($this->getLocaleCodeForDisplayLanguage($locale)), array_flip(preg_split ("/\,/", Settings::getValueByKey("SETTINGS::LOCALE:AVAILABLE"))))) { + $locale = Settings::getValueByKey("SETTINGS::LOCALE:DEFAULT"); } } diff --git a/config/app.php b/config/app.php index 5ed68b37..5292fdb2 100644 --- a/config/app.php +++ b/config/app.php @@ -1,5 +1,7 @@ '0.6.2', @@ -70,16 +72,6 @@ return [ '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), /* |-------------------------------------------------------------------------- @@ -92,47 +84,7 @@ return [ | */ - 'locale' => env('LOCALE', 'en'), - - - /* - |-------------------------------------------------------------------------- - | 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', 'Czech'=>'cs', 'Spanish'=>'es', 'Polish'=>'pl'), - - - /* - |-------------------------------------------------------------------------- - | Unsupported Locales - |-------------------------------------------------------------------------- - | - | Locales the Owner of the Dashboard does not want to support - | - | - */ - - 'unsupported_locales' => env("UNSUPPORTED_LOCALES", ""), - - - /* - |-------------------------------------------------------------------------- - | Datatable Language Setting - |-------------------------------------------------------------------------- - | - | This is the Language-Code used on the Datatables. - | You can grab the Language-Codes from this Website - | https://datatables.net/plug-ins/i18n/ - | - */ - - 'datatable_locale' => env('DATATABLE_LOCALE', 'en-gb'), - + 'locale' =>"en", /* |-------------------------------------------------------------------------- diff --git a/database/seeders/Seeds/SettingsSeeder.php b/database/seeders/Seeds/SettingsSeeder.php index 499349f1..010e76b0 100644 --- a/database/seeders/Seeds/SettingsSeeder.php +++ b/database/seeders/Seeds/SettingsSeeder.php @@ -205,5 +205,46 @@ class SettingsSeeder extends Seeder 'type' => 'string', 'description' => 'The invoice prefix' ]); + + //Locale + Settings::firstOrCreate([ + 'key' => 'SETTINGS::LOCALE:DEFAULT', + ], [ + 'value' => 'en', + 'type' => 'string', + 'description' => 'The default Language the dashboard will be shown in' + ]); + //Dynamic locale + Settings::firstOrCreate([ + 'key' => 'SETTINGS::LOCALE:DYNAMIC', + ], [ + 'value' => 'false', + 'type' => 'boolean', + 'description' => 'If this is true, the Language will change to the Clients browserlanguage or default.' + ]); + //User can change Locale + Settings::firstOrCreate([ + 'key' => 'SETTINGS::LOCALE:CLIENTS_CAN_CHANGE', + ], [ + 'value' => 'false', + 'type' => 'boolean', + 'description' => 'If this is true, the clients will be able to change their Locale.' + ]); + //Locale + Settings::firstOrCreate([ + 'key' => 'SETTINGS::LOCALE:AVAILABLE', + ], [ + 'value' => 'en,de,fr,es', + 'type' => 'string', + 'description' => 'The available languages' + ]); + //Locale + Settings::firstOrCreate([ + 'key' => 'SETTINGS::LOCALE:DATATABLES', + ], [ + 'value' => 'en-gb', + 'type' => 'string', + 'description' => 'The Language of the Datatables. Grab the Language-Codes from here https://datatables.net/plug-ins/i18n/' + ]); } } diff --git a/resources/views/admin/settings/tabs/language.blade.php b/resources/views/admin/settings/tabs/language.blade.php index c9896f24..d163f3bb 100644 --- a/resources/views/admin/settings/tabs/language.blade.php +++ b/resources/views/admin/settings/tabs/language.blade.php @@ -33,8 +33,19 @@ + + + + + +
-
-