-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTranslator.php
More file actions
47 lines (38 loc) · 906 Bytes
/
Translator.php
File metadata and controls
47 lines (38 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace Yokai\EnumBundle\Tests\Unit;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
class Translator implements TranslatorInterface
{
/**
* @var array<string, string>
*/
private array $map;
private string $domain;
/**
* @param array<string, string> $map
*/
public function __construct(array $map, string $domain = 'messages')
{
$this->map = $map;
$this->domain = $domain;
}
public function getLocale(): string
{
return 'fr';
}
public function trans(
string $id,
array $parameters = [],
string|null $domain = null,
string|null $locale = null,
): string {
if ($domain !== $this->domain) {
return $id;
}
return $this->map[$id] ?? $id;
}
}