Language settings. DYNAMC IS STILL MISSING
This commit is contained in:
parent
e6eb7f1e17
commit
831e6a7ee1
7 changed files with 108 additions and 61 deletions
41
app/Classes/Settings/LanguageSettingsC.php
Normal file
41
app/Classes/Settings/LanguageSettingsC.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Classes\Settings;
|
||||
|
||||
use App\Models\Settings;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class LanguageSettingsC
|
||||
{
|
||||
public $tabTitle = 'Language Settings';
|
||||
public $languageSettings;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public function updateLanguageSettings(Request $request)
|
||||
{
|
||||
|
||||
$values=[
|
||||
//SETTINGS::VALUE => 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!');
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Settings;
|
||||
|
||||
return [
|
||||
|
||||
'version' => '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",
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -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/'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,19 @@
|
|||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<label for="datatable-language">Datable Language <i data-toggle="popover"
|
||||
data-trigger="hover"
|
||||
data-content="{{__('The Language of the Datatables. Grab the Language-Codes from here')}} https://datatables.net/plug-ins/i18n/"
|
||||
class="fas fa-info-circle"></i></label>
|
||||
<input x-model="datatable-language" id="datatable-language" name="datatable-language" type="text" required
|
||||
value="{{ App\Models\Settings::getValueByKey("SETTINGS::LOCALE:DATATABLES") }}"
|
||||
class="form-control @error('datatable-language') is-invalid @enderror">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input value="autotranslate" id="autotranslate" name="autotranslate"
|
||||
<input value="true" id="autotranslate" name="autotranslate"
|
||||
type="checkbox">
|
||||
<label for="autotranslate">{{__('Auto-translate')}} <i data-toggle="popover"
|
||||
data-trigger="hover"
|
||||
|
@ -42,7 +53,7 @@
|
|||
class="fas fa-info-circle"></i></label>
|
||||
|
||||
<br/>
|
||||
<input value="canClientChangeLanguage" id="canClientChangeLanguage" name="canClientChangeLanguage"
|
||||
<input value="true" id="canClientChangeLanguage" name="canClientChangeLanguage"
|
||||
type="checkbox">
|
||||
<label for="canClientChangeLanguage">{{__('Let the Client change the Language')}} <i
|
||||
data-toggle="popover"
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
class="fab fa-discord mr-2"></i>{{ __('Discord') }}</a>
|
||||
</li>
|
||||
<!-- Language Selection -->
|
||||
@if(\App\Models\Settings::getValueByKey("SETTINGS::LOCALE:CAN_CLIENT_CHANGE"))
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link" href="#" id="languageDropdown" role="button" data-toggle="dropdown"
|
||||
aria-haspopup="true" aria-expanded="false">
|
||||
|
@ -77,6 +78,7 @@
|
|||
</div>
|
||||
</li>
|
||||
<!-- End Language Selection -->
|
||||
@endif
|
||||
</ul>
|
||||
|
||||
<!-- Right navbar links -->
|
||||
|
|
|
@ -132,7 +132,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
|||
#settings
|
||||
Route::patch('settings/update/icons', [SettingsController::class, 'updateIcons'])->name('settings.update.icons');
|
||||
Route::patch('settings/update/invoice-settings', [\App\Classes\Settings\InvoiceSettingsC::class, 'updateInvoiceSettings'])->name('settings.update.invoicesettings');
|
||||
Route::patch('settings/update/lagnguage', [SettingsController::class, 'updateLanguageSettings'])->name('settings.update.languagesettings');
|
||||
Route::patch('settings/update/language', [\App\Classes\Settings\LanguageSettingsC::class, 'updateLanguageSettings'])->name('settings.update.languagesettings');
|
||||
Route::resource('settings', SettingsController::class)->only('index');
|
||||
|
||||
#invoices
|
||||
|
|
Loading…
Reference in a new issue