Added the ability to dynamically translate on the project website.
This commit is contained in:
23
app/application/app/Services/WebsiteTranslations.php
Normal file
23
app/application/app/Services/WebsiteTranslations.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ProjectLanguage;
|
||||
|
||||
final readonly class WebsiteTranslations
|
||||
{
|
||||
public function __construct(
|
||||
private ProjectLanguage $language,
|
||||
private array $transactions,
|
||||
) { }
|
||||
|
||||
public function translate(string $text): string
|
||||
{
|
||||
return $this->transactions[$text] ?? __($text);
|
||||
}
|
||||
|
||||
public function getLanguage(): ProjectLanguage
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user