generated from boboko/starter
Feature: translations on regions and countries on payment methods
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
label="{{ __('checkout.page.state') }}"
|
label="{{ __('checkout.page.state') }}"
|
||||||
:options="$regions"
|
:options="$regions"
|
||||||
value-field="name"
|
value-field="name"
|
||||||
|
translation-group="states"
|
||||||
:value="$address?->state"
|
:value="$address?->state"
|
||||||
placeholder="{{ __('checkout.page.state_placeholder') }}"
|
placeholder="{{ __('checkout.page.state_placeholder') }}"
|
||||||
required
|
required
|
||||||
@@ -28,7 +29,11 @@
|
|||||||
|
|
||||||
<div class="bbk-field">
|
<div class="bbk-field">
|
||||||
<span class="bbk-field-label">{{ __('checkout.page.country') }}</span>
|
<span class="bbk-field-label">{{ __('checkout.page.country') }}</span>
|
||||||
<p class="bbk-field-static">{{ $storeCountry->name }}</p>
|
<p class="bbk-field-static">
|
||||||
|
{{ \Illuminate\Support\Facades\Lang::has("core::countries.{$storeCountry->name}")
|
||||||
|
? __("core::countries.{$storeCountry->name}")
|
||||||
|
: $storeCountry->name }}
|
||||||
|
</p>
|
||||||
<input type="hidden" name="{{ $prefix }}_country_id" value="{{ $storeCountry->id }}">
|
<input type="hidden" name="{{ $prefix }}_country_id" value="{{ $storeCountry->id }}">
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
@@ -38,6 +43,7 @@
|
|||||||
:name="$prefix . '_country_id'"
|
:name="$prefix . '_country_id'"
|
||||||
label="{{ __('checkout.page.country') }}"
|
label="{{ __('checkout.page.country') }}"
|
||||||
:options="$countries"
|
:options="$countries"
|
||||||
|
translation-group="countries"
|
||||||
:value="$address?->country_id"
|
:value="$address?->country_id"
|
||||||
placeholder="{{ __('checkout.page.country_placeholder') }}"
|
placeholder="{{ __('checkout.page.country_placeholder') }}"
|
||||||
required
|
required
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
{{--
|
{{--
|
||||||
<x-checkout::select name="billing_country_id" label="Country" :options="$countries" required />
|
<x-checkout::select name="billing_country_id" label="Country" :options="$countries" required />
|
||||||
<x-checkout::select name="shipping_state" label="Region" :options="$regions" value-field="name" required />
|
<x-checkout::select name="shipping_state" label="Region" :options="$regions" value-field="name" translation-group="states" required />
|
||||||
|
|
||||||
`options` is an iterable of models/objects; `label` is always read from
|
`options` is an iterable of models/objects; `label` is always read from
|
||||||
`->name`, the submitted value from `->{$valueField}` (default `id`, but e.g.
|
`->name`, the submitted value from `->{$valueField}` (default `id`, but e.g.
|
||||||
`name` for Lunar states — table-rate-shipping resolves those with
|
`name` for Lunar states — table-rate-shipping resolves those with
|
||||||
State::whereName(), so the address must carry the exact name string).
|
State::whereName(), so the address must carry the exact name string).
|
||||||
|
|
||||||
|
`translationGroup` (optional, e.g. "countries"/"states") looks the raw
|
||||||
|
`->name` up in boboko-core's `core::{group}.{name}` lang file (see
|
||||||
|
boboko-core's lang/el/countries.php, lang/el/states.php) for the
|
||||||
|
DISPLAYED label only — the submitted `value` is always the untranslated
|
||||||
|
`->{$valueField}`, since table-rate-shipping/Lunar's Country lookups key
|
||||||
|
off the original English name. Falls back to the raw name when no
|
||||||
|
translation exists for the current locale (e.g. English, or a country
|
||||||
|
outside the covered set).
|
||||||
--}}
|
--}}
|
||||||
@props([
|
@props([
|
||||||
'name',
|
'name',
|
||||||
@@ -15,8 +24,21 @@
|
|||||||
'placeholder' => null,
|
'placeholder' => null,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'valueField' => 'id',
|
'valueField' => 'id',
|
||||||
|
'translationGroup' => null,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@php
|
||||||
|
$optionLabel = function ($option) use ($translationGroup) {
|
||||||
|
if (! $translationGroup) {
|
||||||
|
return $option->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = "core::{$translationGroup}.{$option->name}";
|
||||||
|
|
||||||
|
return \Illuminate\Support\Facades\Lang::has($key) ? __($key) : $option->name;
|
||||||
|
};
|
||||||
|
@endphp
|
||||||
|
|
||||||
@php($selected = old($name, $value))
|
@php($selected = old($name, $value))
|
||||||
|
|
||||||
<div class="bbk-field">
|
<div class="bbk-field">
|
||||||
@@ -32,7 +54,7 @@
|
|||||||
@endif
|
@endif
|
||||||
@foreach ($options as $option)
|
@foreach ($options as $option)
|
||||||
<option value="{{ $option->{$valueField} }}" @selected((string) $selected === (string) $option->{$valueField})>
|
<option value="{{ $option->{$valueField} }}" @selected((string) $selected === (string) $option->{$valueField})>
|
||||||
{{ $option->name }}
|
{{ $optionLabel($option) }}
|
||||||
</option>
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
@checked($selected === $method->type)
|
@checked($selected === $method->type)
|
||||||
data-action="change->bbk-payment#selectMethod"
|
data-action="change->bbk-payment#selectMethod"
|
||||||
>
|
>
|
||||||
<span class="bbk-checkout-payment-option-name">{{ $method->name }}</span>
|
<span class="bbk-checkout-payment-option-name">{{ $method->translate('name') }}</span>
|
||||||
</label>
|
</label>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user