| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Loader; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\MessageCatalogue; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
class ArrayLoader implements LoaderInterface |
| 22 |
{ |
| 23 |
public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue |
| 24 |
{ |
| 25 |
$resource = $this->flatten($resource); |
| 26 |
$catalogue = new MessageCatalogue($locale); |
| 27 |
$catalogue->add($resource, $domain); |
| 28 |
|
| 29 |
return $catalogue; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
private function flatten(array $messages): array |
| 41 |
{ |
| 42 |
$result = []; |
| 43 |
foreach ($messages as $key => $value) { |
| 44 |
if (\is_array($value)) { |
| 45 |
foreach ($this->flatten($value) as $k => $v) { |
| 46 |
if (null !== $v) { |
| 47 |
$result[$key.'.'.$k] = $v; |
| 48 |
} |
| 49 |
} |
| 50 |
} elseif (null !== $value) { |
| 51 |
$result[$key] = $value; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
return $result; |
| 56 |
} |
| 57 |
} |