Skip to content

Commit

Permalink
LocalizedString
Browse files Browse the repository at this point in the history
  • Loading branch information
cevro committed Jul 31, 2023
1 parent a5ecc4b commit 4fcf013
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Localization/LocalizedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,43 @@

namespace Fykosak\Utils\Localization;

/**
* @template L of string
*/
class LocalizedString
{
/**
* @phpstan-var array<string,string>
* @phpstan-var array<L,string>
*/
private array $texts;

/**
* @phpstan-param array<string,string> $texts
* @phpstan-param array<L,string> $texts
*/
public function __construct(array $texts)
{
$this->texts = $texts;
}

/**
* @phpstan-param L $lang
*/
public function __get(string $lang): ?string
{
return $this->getText($lang);
}

/**
* @phpstan-param L $lang
*/
public function getText(string $lang): ?string
{
return $this->texts[$lang] ?? null;
}

/**
* @phpstan-return array<L,string>
*/
public function __serialize(): array
{
return $this->texts;
Expand Down

0 comments on commit 4fcf013

Please sign in to comment.