| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Reader; |
| 13 |
|
| 14 |
use Symfony\Component\Finder\Finder; |
| 15 |
use Symfony\Component\Translation\Loader\LoaderInterface; |
| 16 |
use Symfony\Component\Translation\MessageCatalogue; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class TranslationReader implements TranslationReaderInterface |
| 24 |
{ |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
private array $loaders = []; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function addLoader(string $format, LoaderInterface $loader): void |
| 38 |
{ |
| 39 |
$this->loaders[$format] = $loader; |
| 40 |
} |
| 41 |
|
| 42 |
public function read(string $directory, MessageCatalogue $catalogue): void |
| 43 |
{ |
| 44 |
if (!is_dir($directory)) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
foreach ($this->loaders as $format => $loader) { |
| 49 |
|
| 50 |
$finder = new Finder(); |
| 51 |
$extension = $catalogue->getLocale().'.'.$format; |
| 52 |
$files = $finder->files()->name('*.'.$extension)->in($directory); |
| 53 |
foreach ($files as $file) { |
| 54 |
$domain = substr($file->getFilename(), 0, -1 * \strlen($extension) - 1); |
| 55 |
$catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain)); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |