24 lines
592 B
PHP
24 lines
592 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Services\ProjectTranslation;
|
|
|
|
use App\Models\ProjectLanguage;
|
|
|
|
final readonly class TranslationText
|
|
{
|
|
public function __construct(
|
|
private ProjectLanguage $language,
|
|
private array $translations,
|
|
) { }
|
|
|
|
public static function init(ProjectLanguage $language, array $translations): self
|
|
{
|
|
return new self($language, $translations);
|
|
}
|
|
|
|
public function translate(string $code): string
|
|
{
|
|
return $this->translations[$code] ?? __($code, [], $this->language->system_lang?->getLocale());
|
|
}
|
|
}
|