40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace KorElf\TranslateLaravel\DTO;
|
|
|
|
final class PartText
|
|
{
|
|
private array $texts = [];
|
|
private array $beforeTexts = [];
|
|
private array $afterTexts = [];
|
|
private int $part = 0;
|
|
|
|
public function add(string $text, ?string $beforeText = null, ?string $afterText = null): void
|
|
{
|
|
$this->texts[$this->part] = $text;
|
|
$this->beforeTexts[$this->part] = $beforeText;
|
|
$this->afterTexts[$this->part] = $afterText;
|
|
|
|
$this->part++;
|
|
}
|
|
|
|
public function getTextsForTranslation(): array
|
|
{
|
|
return $this->texts;
|
|
}
|
|
|
|
public function getTextsAfterTranslation(array $texts): string
|
|
{
|
|
$result = '';
|
|
foreach ($texts as $key => $text) {
|
|
if ($this->beforeTexts[$key] !== null) {
|
|
$result .= $this->beforeTexts[$key];
|
|
}
|
|
$result .= $text;
|
|
if ($this->afterTexts[$key] !== null) {
|
|
$result .= $this->afterTexts[$key];
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
} |