Skip to content

Commit 2162f5b

Browse files
committed
upgrade laraeast/laravel-locales version to v4.1
1 parent 501a34a commit 2162f5b

File tree

9 files changed

+47
-35
lines changed

9 files changed

+47
-35
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^8.1",
19-
"laraeast/laravel-locales": "^3.3",
19+
"laraeast/laravel-locales": "^4.1",
2020
"spatie/laravel-html": "^3.5"
2121
},
2222
"require-dev": {

src/BsForm.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Laraeast\LaravelBootstrapForms;
44

55
use Laraeast\LaravelBootstrapForms\Components\Base64ImageComponent;
6+
use Laraeast\LaravelLocales\Enums\Language;
67
use Laraeast\LaravelLocales\Facades\Locales;
78
use Laraeast\LaravelBootstrapForms\Traits\HasOpenAndClose;
89
use Laraeast\LaravelBootstrapForms\Components\FileComponent;
@@ -28,9 +29,12 @@ class BsForm
2829

2930
private string $resource = '';
3031

32+
/**
33+
* @var array|\Laraeast\LaravelLocales\Enums\Language[]
34+
*/
3135
protected array $locales = [];
3236

33-
protected \stdClass|array|null $locale = null;
37+
protected Language|null $locale = null;
3438

3539
/**
3640
* The component style.
@@ -113,8 +117,10 @@ public function __call(string $name, array $arguments): mixed
113117
/**
114118
* Set the default locale code.
115119
*/
116-
public function locale(\stdClass|array|null $locale = null): self
120+
public function locale(string|Language|null $locale = null): self
117121
{
122+
$locale = $locale ? Locales::from($locale) : null;
123+
118124
$this->locale = $locale;
119125

120126
return $this;
@@ -180,7 +186,7 @@ public static function getInstance(): self
180186
}
181187

182188
/**
183-
* @return array
189+
* @return \Laraeast\LaravelLocales\Enums\Language[]
184190
*/
185191
public function getLocales(): array
186192
{

src/Contracts/Components/LocalizableComponent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Laraeast\LaravelBootstrapForms\Contracts\Components;
44

5+
use Laraeast\LaravelLocales\Enums\Language;
6+
57
interface LocalizableComponent
68
{
79
/**
810
* Add the given lang to the name attribute.
911
*/
10-
public function locale(\stdClass|array|null $locale = null): self;
12+
public function locale(Language|string|null $locale = null): self;
1113
}

src/Facades/BsForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @method static \Laraeast\LaravelBootstrapForms\Components\SubmitComponent submit(?string $label = null, ?string $name = null, mixed $value = null)
2424
* @method static \Laraeast\LaravelBootstrapForms\BsForm|self open(string $url, array $attributes = [])
2525
* @method static \Laraeast\LaravelBootstrapForms\BsForm|self resource(string $resource)
26-
* @method static array|null locale(?string $locale = null)
26+
* @method static array|null locale(?\Laraeast\LaravelLocales\Enums\Language|string $locale = null)
2727
* @method static \Laraeast\LaravelBootstrapForms\BsForm|self style(?string $style = null)
2828
* @method static \Laraeast\LaravelBootstrapForms\BsForm|self clearStyle()
2929
* @method static \Laraeast\LaravelBootstrapForms\BsForm|self inlineValidation(bool $bool = true)

src/Helpers/FormDirectives.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Str;
66
use Illuminate\Support\Facades\Blade;
77
use Illuminate\Support\Facades\Config;
8+
use Laraeast\LaravelBootstrapForms\Facades\BsForm;
89

910
class FormDirectives
1011
{
@@ -20,7 +21,7 @@ public static function register(): void
2021

2122
$initLoop = "\$__env->startComponent('$view', ['uniqid' => '$uniqid']); \$__currentLoopData = BsForm::getLocales(); \$__env->addLoop(\$__currentLoopData);";
2223

23-
$iterateLoop = "\$__env->startPush('$uniqid'.\$locale->code); \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); BsForm::locale(\$locale);";
24+
$iterateLoop = "\$__env->startPush('$uniqid'.\$locale->getCode()); \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); BsForm::locale(\$locale);";
2425

2526
return "<?php {$initLoop} foreach(\$__currentLoopData as \$locale): {$iterateLoop} ?>";
2627
});

src/Traits/LocalizableComponent.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Laraeast\LaravelBootstrapForms\Traits;
44

5+
use Laraeast\LaravelLocales\Enums\Language;
6+
use Laraeast\LaravelLocales\Facades\Locales;
7+
58
trait LocalizableComponent
69
{
7-
protected \stdClass|array|null $locale = null;
10+
protected Language|null $locale = null;
811

912
/**
1013
* Determine if the label will be translated or not.
@@ -14,9 +17,9 @@ trait LocalizableComponent
1417
/**
1518
* Add the given lang to the name attribute.
1619
*/
17-
public function locale(\stdClass|array|null $locale = null): self
20+
public function locale(Language|string|null $locale = null): self
1821
{
19-
$this->locale = $locale;
22+
$this->locale = $locale ? Locales::from($locale) : null;
2023

2124
$this->setDefaultLabel();
2225

@@ -39,13 +42,13 @@ protected function transformProperties(array $properties): array
3942

4043
$nameHasBrackets = $this->nameHasBrackets;
4144

42-
if ($locale->code) {
43-
$properties['nameWithoutBrackets'] = "{$this->nameWithoutBrackets}:{$this->locale->code}";
45+
if ($locale->getCode()) {
46+
$properties['nameWithoutBrackets'] = "{$this->nameWithoutBrackets}:{$this->locale->getCode()}";
4447

4548
if ($nameHasBrackets) {
46-
$properties['name'] = "{$this->nameWithoutBrackets}:{$this->locale->code}[]";
49+
$properties['name'] = "{$this->nameWithoutBrackets}:{$this->locale->getCode()}[]";
4750
} else {
48-
$properties['name'] = "{$this->nameWithoutBrackets}:{$this->locale->code}";
51+
$properties['name'] = "{$this->nameWithoutBrackets}:{$this->locale->getCode()}";
4952
}
5053
}
5154

src/views/bootstrap3/components/multilingual-tabs.blade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<ul class="nav nav-tabs" role="tablist">
44
@multilingualForm
55
<li role="presentation" class="{{ $loop->index == 0 ? 'active' : '' }}">
6-
<a href="#{{ $uniqid.'-'.$locale->code }}" aria-controls="{{ $uniqid.'-'.$locale->code }}" role="tab" data-toggle="tab">
7-
<img src="{{ $locale->flag }}" alt="">
8-
{{ $locale->name }}
6+
<a style="display:flex;align-items: center;" href="#{{ $uniqid.'-'.$locale->getCode() }}" aria-controls="{{ $uniqid.'-'.$locale->getCode() }}" role="tab" data-toggle="tab">
7+
{{ $locale->getSvgFlag(24, 24) }}
8+
<span style="margin-left: 1rem;">{{ $locale->getName() }}</span>
99
</a>
1010
</li>
1111
@endMultilingualForm
@@ -14,8 +14,8 @@
1414
<!-- Tab panes -->
1515
<div class="tab-content" style="margin-top: 10px;">
1616
@multilingualForm
17-
<div role="tabpanel" class="tab-pane fade{{ $loop->index == 0 ? ' active in' : '' }}" id="{{ $uniqid.'-'.$locale->code }}">
18-
@stack($uniqid.$locale->code)
17+
<div role="tabpanel" class="tab-pane fade{{ $loop->index == 0 ? ' active in' : '' }}" id="{{ $uniqid.'-'.$locale->getCode() }}">
18+
@stack($uniqid.$locale->getCode())
1919
</div>
2020
@endMultilingualForm
2121
</div>

src/views/bootstrap4/components/multilingual-tabs.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
@multilingualForm
44
<li class="nav-item">
55
<a class="nav-link{{ $loop->index == 0 ? ' active' : '' }}"
6-
id="{{ $tabuniqid.'-'.$locale->code }}-tab"
6+
id="{{ $tabuniqid.'-'.$locale->getCode() }}-tab"
77
data-toggle="tab"
8-
href="#{{ $tabuniqid.'-'.$locale->code }}"
8+
href="#{{ $tabuniqid.'-'.$locale->getCode() }}"
99
role="tab"
10-
aria-controls="{{ $tabuniqid.'-'.$locale->code }}"
10+
aria-controls="{{ $tabuniqid.'-'.$locale->getCode() }}"
1111
aria-selected="{{ $loop->index == 0 ? 'true' : 'false' }}">
12-
<img src="{{ $locale->flag }}" class="mx-1" alt="">
13-
{{ $locale->name }}
12+
{{ $locale->getSvgFlag(24, 24) }}
13+
<span class="ml-2">{{ $locale->getName() }}</span>
1414
</a>
1515
</li>
1616
@endMultilingualForm
1717
</ul>
1818
<div class="tab-content" id="{{ $tabuniqid }}-content">
1919
@multilingualForm
2020
<div class="tab-pane fade{{ $loop->index == 0 ? ' show active' : '' }}"
21-
id="{{ $tabuniqid.'-'.$locale->code }}"
21+
id="{{ $tabuniqid.'-'.$locale->getCode() }}"
2222
role="tabpanel"
23-
aria-labelledby="{{ $tabuniqid.'-'.$locale->code }}-tab">
23+
aria-labelledby="{{ $tabuniqid.'-'.$locale->getCode() }}-tab">
2424
<div class="py-2">
25-
@stack($uniqid.$locale->code)
25+
@stack($uniqid.$locale->getCode())
2626
</div>
2727
</div>
2828
@endMultilingualForm

src/views/bootstrap5/components/multilingual-tabs.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
@multilingualForm
44
<li class="nav-item" role="presentation">
55
<button class="nav-link{{ $loop->index == 0 ? ' active' : '' }}"
6-
id="{{ $tabuniqid.'-'.$locale->code }}-tab"
6+
id="{{ $tabuniqid.'-'.$locale->getCode() }}-tab"
77
data-bs-toggle="tab"
8-
data-bs-target="#{{ $tabuniqid.'-'.$locale->code }}"
8+
data-bs-target="#{{ $tabuniqid.'-'.$locale->getCode() }}"
99
type="button"
1010
role="tab"
11-
aria-controls="{{ $tabuniqid.'-'.$locale->code }}"
11+
aria-controls="{{ $tabuniqid.'-'.$locale->getCode() }}"
1212
aria-selected="{{ $loop->index == 0 ? 'true' : 'false' }}">
13-
<img src="{{ $locale->flag }}" class="mx-1" alt="">
14-
{{ $locale->name }}
13+
{{ $locale->getSvgFlag(24, 24) }}
14+
<span class="ms-2">{{ $locale->getName() }}</span>
1515
</button>
1616
</li>
1717
@endMultilingualForm
1818
</ul>
1919
<div class="tab-content" id="{{ $tabuniqid }}-content">
2020
@multilingualForm
2121
<div class="tab-pane fade{{ $loop->index == 0 ? ' show active' : '' }}"
22-
id="{{ $tabuniqid.'-'.$locale->code }}"
22+
id="{{ $tabuniqid.'-'.$locale->getCode() }}"
2323
role="tabpanel"
24-
aria-labelledby="{{ $tabuniqid.'-'.$locale->code }}-tab">
24+
aria-labelledby="{{ $tabuniqid.'-'.$locale->getCode() }}-tab">
2525
<div class="py-2">
26-
@stack($uniqid.$locale->code)
26+
@stack($uniqid.$locale->getCode())
2727
</div>
2828
</div>
2929
@endMultilingualForm

0 commit comments

Comments
 (0)