Completed Multi Lang Support & Refactoring Pending

This commit is contained in:
devansh bawari 2021-06-08 13:01:08 +05:30
parent dace5f9ecb
commit 03eeafc5de
4 changed files with 35 additions and 35 deletions

View File

@ -64,8 +64,8 @@
$field['options'] = ''; $field['options'] = '';
} }
$selectedOption = core()->getConfigData($name) ?? ''; $selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
$dependSelectedOption = core()->getConfigData(implode('.', [$firstField, $secondField, $thirdField, $dependField])) ?? ''; $dependSelectedOption = core()->getConfigData(implode('.', [$firstField, $secondField, $thirdField, $dependField]), $channel, $locale) ?? '';
?> ?>
@if (strpos($field['validation'], 'required_if') !== false) @if (strpos($field['validation'], 'required_if') !== false)
@ -110,31 +110,31 @@
@if ($field['type'] == 'text') @if ($field['type'] == 'text')
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: (core()->getConfigData($name) ? core()->getConfigData($name) : (isset($field['default_value']) ? $field['default_value'] : '')) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;"> <input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: (core()->getConfigData($name, $channel, $locale) ? core()->getConfigData($name, $channel, $locale) : (isset($field['default_value']) ? $field['default_value'] : '')) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'password') @elseif ($field['type'] == 'password')
<input type="password" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;"> <input type="password" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'number') @elseif ($field['type'] == 'number')
<input type="number" min="0" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;"> <input type="number" min="0" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'color') @elseif ($field['type'] == 'color')
<input type="color" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;"> <input type="color" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">
@elseif ($field['type'] == 'textarea') @elseif ($field['type'] == 'textarea')
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">{{ old($name) ?: core()->getConfigData($name) ?: (isset($field['default_value']) ? $field['default_value'] : '') }}</textarea> <textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;">{{ old($name) ?: core()->getConfigData($name, $channel, $locale) ?: (isset($field['default_value']) ? $field['default_value'] : '') }}</textarea>
@elseif ($field['type'] == 'select') @elseif ($field['type'] == 'select')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" > <select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" >
<?php <?php
$selectedOption = core()->getConfigData($name) ?? ''; $selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
?> ?>
@if (isset($field['repository'])) @if (isset($field['repository']))
@ -172,7 +172,7 @@
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" multiple> <select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" multiple>
<?php <?php
$selectedOption = core()->getConfigData($name) ?? ''; $selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
?> ?>
@if (isset($field['repository'])) @if (isset($field['repository']))
@ -208,7 +208,7 @@
@elseif ($field['type'] == 'country') @elseif ($field['type'] == 'country')
<?php <?php
$countryCode = core()->getConfigData($name) ?? ''; $countryCode = core()->getConfigData($name, $channel, $locale) ?? '';
?> ?>
<country <country
@ -220,7 +220,7 @@
@elseif ($field['type'] == 'state') @elseif ($field['type'] == 'state')
<?php <?php
$stateCode = core()->getConfigData($name) ?? ''; $stateCode = core()->getConfigData($name, $channel, $locale) ?? '';
?> ?>
<state <state
@ -231,7 +231,7 @@
@elseif ($field['type'] == 'boolean') @elseif ($field['type'] == 'boolean')
<?php $selectedOption = core()->getConfigData($name) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?> <?php $selectedOption = core()->getConfigData($name, $channel, $locale) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?>
<label class="switch"> <label class="switch">
<input type="hidden" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="0" /> <input type="hidden" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="0" />
@ -242,8 +242,8 @@
@elseif ($field['type'] == 'image') @elseif ($field['type'] == 'image')
<?php <?php
$src = Storage::url(core()->getConfigData($name)); $src = Storage::url(core()->getConfigData($name, $channel, $locale));
$result = core()->getConfigData($name); $result = core()->getConfigData($name, $channel, $locale);
?> ?>
@if ($result) @if ($result)
@ -252,7 +252,7 @@
</a> </a>
@endif @endif
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;"> <input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result) @if ($result)
<div class="control-group" style="margin-top: 5px;"> <div class="control-group" style="margin-top: 5px;">
@ -268,7 +268,7 @@
@elseif ($field['type'] == 'file') @elseif ($field['type'] == 'file')
<?php <?php
$result = core()->getConfigData($name); $result = core()->getConfigData($name, $channel, $locale);
$src = explode("/", $result); $src = explode("/", $result);
$path = end($src); $path = end($src);
?> ?>
@ -279,7 +279,7 @@
</a> </a>
@endif @endif
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;"> <input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result) @if ($result)
<div class="control-group" style="margin-top: 5px;"> <div class="control-group" style="margin-top: 5px;">

View File

@ -7,14 +7,13 @@
@section('content') @section('content')
<div class="content"> <div class="content">
@php @php
$locale = request()->get('locale') ?: app()->getLocale(); /* getting channel and locales */
$channel = request()->get('channel') ?: core()->getDefaultChannelCode(); $mainConfigurations = core()->getChannelCodeAndLocaleCode();
$channelLocales = app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales; /* assigning */
$locale = $mainConfigurations['localeCode'];
if (! $channelLocales->contains('code', $locale)) { $channel = $mainConfigurations['channelCode'];
$locale = config('app.fallback_locale'); $channelLocales = $mainConfigurations['channelLocales'];
}
@endphp @endphp
<form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data"> <form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">

View File

@ -41,8 +41,12 @@ class ConfigurationController extends Controller
$this->velocityHelper = app('Webkul\Velocity\Helpers\Helper'); $this->velocityHelper = app('Webkul\Velocity\Helpers\Helper');
$this->velocityMetaDataRepository = $velocityMetadataRepository; $this->velocityMetaDataRepository = $velocityMetadataRepository;
$this->locale = request()->get('locale') ?: app()->getLocale(); /* getting channel and locales */
$this->channel = request()->get('channel') ?: 'default'; $mainConfigurations = core()->getChannelCodeAndLocaleCode();
/* assigning */
$this->locale = $mainConfigurations['localeCode'];
$this->channel = $mainConfigurations['channelCode'];
} }
/** /**
@ -52,8 +56,6 @@ class ConfigurationController extends Controller
*/ */
public function renderMetaData() public function renderMetaData()
{ {
$this->locale = request()->get('locale') ? request()->get('locale') : app()->getLocale();
$velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, $this->channel, false); $velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, $this->channel, false);
if (! $velocityMetaData) { if (! $velocityMetaData) {

View File

@ -5,14 +5,13 @@
@stop @stop
@php @php
$locale = request()->get('locale') ?: app()->getLocale(); /* getting channel and locales */
$channel = request()->get('channel') ?: core()->getDefaultChannelCode(); $mainConfigurations = core()->getChannelCodeAndLocaleCode();
$channelLocales = app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales; /* assigning */
$locale = $mainConfigurations['localeCode'];
if (! $channelLocales->contains('code', $locale)) { $channel = $mainConfigurations['channelCode'];
$locale = config('app.fallback_locale'); $channelLocales = $mainConfigurations['channelLocales'];
}
@endphp @endphp
@section('content') @section('content')