extending TrashedFilter (translation with variable)
Hi all,
I'm extending the TrashedFilter on a table to create a "ArchivedFilter".
Below is my class, the problem i now have is that the "$this->getPlural()" is null, and than my translation is not complete.
i'm probably forgetting something, so hopefully somebody can point me in the right direction.
Usage
Class
lang/nl/filters.php
I'm extending the TrashedFilter on a table to create a "ArchivedFilter".
Below is my class, the problem i now have is that the "$this->getPlural()" is null, and than my translation is not complete.
i'm probably forgetting something, so hopefully somebody can point me in the right direction.
Usage
ArchivedFilter::make()
->plural('services'),ArchivedFilter::make()
->plural('services'),Class
class ArchivedFilter extends TrashedFilter
{
protected string|Closure|null $plural = null;
protected function setUp(): void
{
parent::setUp();
$this->label(__('filters.archived.label', ['plural' => $this->getPlural()]));
$this->placeholder(__('filters.archived.without_trashed', ['plural' => $this->getPlural()]));
$this->trueLabel(__('filters.archived.with_trashed', ['plural' => $this->getPlural()]));
$this->falseLabel(__('filters.archived.only_trashed', ['plural' => $this->getPlural()]));
}
public function plural(string|Closure|null $plural): static
{
$this->plural = $plural;
return $this;
}
public function getPlural(): ?string
{
return $this->evaluate($this->plural);
}
}class ArchivedFilter extends TrashedFilter
{
protected string|Closure|null $plural = null;
protected function setUp(): void
{
parent::setUp();
$this->label(__('filters.archived.label', ['plural' => $this->getPlural()]));
$this->placeholder(__('filters.archived.without_trashed', ['plural' => $this->getPlural()]));
$this->trueLabel(__('filters.archived.with_trashed', ['plural' => $this->getPlural()]));
$this->falseLabel(__('filters.archived.only_trashed', ['plural' => $this->getPlural()]));
}
public function plural(string|Closure|null $plural): static
{
$this->plural = $plural;
return $this;
}
public function getPlural(): ?string
{
return $this->evaluate($this->plural);
}
}lang/nl/filters.php
return [
'archived' => [
'label' => 'Gearchiveerde :plural',
'without_trashed' => 'Zonder gearchiveerde :plural',
'with_trashed' => 'Met gearchiveerde :plural',
'only_trashed' => 'Alleen gearchiveerde :plural',
],
];return [
'archived' => [
'label' => 'Gearchiveerde :plural',
'without_trashed' => 'Zonder gearchiveerde :plural',
'with_trashed' => 'Met gearchiveerde :plural',
'only_trashed' => 'Alleen gearchiveerde :plural',
],
];Solution
i found it.
It was as simple as needing to use a closure.
It was as simple as needing to use a closure.
protected function setUp(): void
{
parent::setUp();
$this->label(fn () => __('filters.archived.label', [
'plural' => $this->getPlural(),
]));
$this->placeholder(fn () => __('filters.archived.without_trashed', [
'plural' => $this->getPlural(),
]));
$this->trueLabel(fn () => __('filters.archived.with_trashed', [
'plural' => $this->getPlural(),
]));
$this->falseLabel(fn () => __('filters.archived.only_trashed', [
'plural' => $this->getPlural(),
]));
} protected function setUp(): void
{
parent::setUp();
$this->label(fn () => __('filters.archived.label', [
'plural' => $this->getPlural(),
]));
$this->placeholder(fn () => __('filters.archived.without_trashed', [
'plural' => $this->getPlural(),
]));
$this->trueLabel(fn () => __('filters.archived.with_trashed', [
'plural' => $this->getPlural(),
]));
$this->falseLabel(fn () => __('filters.archived.only_trashed', [
'plural' => $this->getPlural(),
]));
}