38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace app\View\Components\Site;
|
|
|
|
use App\Enums\CacheTag;
|
|
use App\Models\Project;
|
|
use App\Services\WebsiteTranslations;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\View\Component;
|
|
use Illuminate\View\View;
|
|
|
|
final class ChooseLanguage extends Component
|
|
{
|
|
public function __construct(
|
|
private readonly WebsiteTranslations $websiteTranslations,
|
|
private readonly Project $project,
|
|
) { }
|
|
|
|
public function render(): View
|
|
{
|
|
$link = Str::of( request()->url() )->rtrim('/');
|
|
if ($link->endsWith('/language/' . $this->websiteTranslations->getLanguage()->code)) {
|
|
$link = $link->replace('/language/' . $this->websiteTranslations->getLanguage()->code, '', false);
|
|
}
|
|
|
|
$seconds = 3600 * 12;
|
|
$languages = CacheTag::Project->getCache()->remember(self::class . $this->project->id, $seconds, function () {
|
|
return $this->project->languages;
|
|
});
|
|
|
|
return view('components.site.choose-language', [
|
|
'websiteTranslations' => $this->websiteTranslations,
|
|
'languages' => $languages,
|
|
'link' => (string) $link,
|
|
]);
|
|
}
|
|
}
|