|
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
|
|
|
public function __construct(TranslationLoader $loader) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->loader = $loader; |
|
39
|
|
|
} |
|
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
|
|
|
public function getCatalogues(Configuration $config, array $locales = []) |
|
50
|
|
|
{ |
|
51
|
|
|
$dirs = $config->getPathsToTranslationFiles(); |
|
52
|
|
|
if (empty($locales)) { |
|
53
|
|
|
$locales = $config->getLocales(); |
|
54
|
|
|
} |
|
55
|
|
|
$catalogues = []; |
|
56
|
|
|
foreach ($locales as $locale) { |
|
57
|
|
|
$currentCatalogue = new MessageCatalogue($locale); |
|
58
|
|
|
foreach ($dirs as $path) { |
|
59
|
|
|
if (is_dir($path)) { |
|
60
|
|
|
$this->loader->loadMessages($path, $currentCatalogue); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
$catalogues[] = $currentCatalogue; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $catalogues; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|