1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Catalogue; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader; |
15
|
|
|
use Symfony\Component\Translation\MessageCatalogue; |
16
|
|
|
use Translation\Bundle\Model\Configuration; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Fetches catalogues from source files. This will only work with local file storage |
20
|
|
|
* and the actions are read only. |
21
|
|
|
* |
22
|
|
|
* This should be considered as a "ReadFromCache" service. |
23
|
|
|
* |
24
|
|
|
* @author Tobias Nyholm <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class CatalogueFetcher |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var TranslationLoader |
30
|
|
|
*/ |
31
|
|
|
private $loader; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param TranslationLoader $loader |
35
|
|
|
*/ |
36
|
6 |
|
public function __construct(TranslationLoader $loader) |
37
|
|
|
{ |
38
|
6 |
|
$this->loader = $loader; |
39
|
6 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* load any existing messages from the translation files. |
43
|
|
|
* |
44
|
|
|
* @param Configuration $config |
45
|
|
|
* @param array $locales |
46
|
|
|
* |
47
|
|
|
* @return MessageCatalogue[] |
48
|
|
|
*/ |
49
|
2 |
|
public function getCatalogues(Configuration $config, array $locales = []) |
50
|
|
|
{ |
51
|
2 |
|
$dirs = $config->getPathsToTranslationFiles(); |
52
|
2 |
|
if (empty($locales)) { |
53
|
2 |
|
$locales = $config->getLocales(); |
54
|
2 |
|
} |
55
|
2 |
|
$catalogues = []; |
56
|
2 |
|
foreach ($locales as $locale) { |
57
|
2 |
|
$currentCatalogue = new MessageCatalogue($locale); |
58
|
2 |
|
foreach ($dirs as $path) { |
59
|
2 |
|
if (is_dir($path)) { |
60
|
2 |
|
$this->loader->loadMessages($path, $currentCatalogue); |
61
|
2 |
|
} |
62
|
2 |
|
} |
63
|
2 |
|
$catalogues[] = $currentCatalogue; |
64
|
2 |
|
} |
65
|
|
|
|
66
|
2 |
|
return $catalogues; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|