1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\SettingsModule\Helper; |
15
|
|
|
|
16
|
|
|
use Zikula\Bundle\CoreBundle\CacheClearer; |
17
|
|
|
use Zikula\Bundle\CoreBundle\DynamicConfigDumper; |
18
|
|
|
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; |
19
|
|
|
|
20
|
|
|
class TranslationConfigHelper |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ZikulaHttpKernelInterface |
24
|
|
|
*/ |
25
|
|
|
private $kernel; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var DynamicConfigDumper |
29
|
|
|
*/ |
30
|
|
|
private $configDumper; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var CacheClearer |
34
|
|
|
*/ |
35
|
|
|
private $cacheClearer; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $installed; |
41
|
|
|
|
42
|
|
|
public function __construct( |
43
|
|
|
ZikulaHttpKernelInterface $kernel, |
44
|
|
|
DynamicConfigDumper $configDumper, |
45
|
|
|
CacheClearer $cacheClearer, |
46
|
|
|
bool $installed = false |
47
|
|
|
) { |
48
|
|
|
$this->kernel = $kernel; |
49
|
|
|
$this->configDumper = $configDumper; |
50
|
|
|
$this->cacheClearer = $cacheClearer; |
51
|
|
|
$this->installed = $installed; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function updateConfiguration() |
55
|
|
|
{ |
56
|
|
|
$configName = 'translation'; |
57
|
|
|
$transConfigOld = $this->configDumper->getConfiguration($configName); |
58
|
|
|
$transConfigNew = [ |
59
|
|
|
'configs' => [ |
60
|
|
|
'zikula' => $transConfigOld['configs']['zikula'], |
61
|
|
|
'extension' => $transConfigOld['configs']['extension'] |
62
|
|
|
] |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
if (file_exists($this->kernel->getProjectDir() . '/src/system')) { |
66
|
|
|
// development system: core bundles and system modules are in "src/" |
67
|
|
|
$transConfigNew['configs']['zikula']['dirs'] = [ |
68
|
|
|
'%kernel.project_dir%/templates', |
69
|
|
|
'%kernel.project_dir%/src/system', |
70
|
|
|
'%kernel.project_dir%/src/Zikula' |
71
|
|
|
]; |
72
|
|
|
// note we can not set this in a distribution system when core components are in "vendor/" |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if ($this->installed) { |
76
|
|
|
$configTemplate = [ |
77
|
|
|
'excluded_names' => ['*TestCase.php', '*Test.php'], |
78
|
|
|
'excluded_dirs' => ['vendor'], |
79
|
|
|
'output_format' => 'yaml', |
80
|
|
|
'local_file_storage_options' => [ |
81
|
|
|
'default_output_format' => 'yaml' |
82
|
|
|
] |
83
|
|
|
]; |
84
|
|
|
foreach ($this->kernel->getModules() as $bundle) { |
85
|
|
|
if ($this->kernel->isCoreExtension($bundle->getName())) { |
86
|
|
|
continue; |
87
|
|
|
} |
88
|
|
|
$bundleConfig = $configTemplate; |
89
|
|
|
$translationDirectory = $bundle->getPath() . '/Resources/translations'; |
90
|
|
|
$bundleConfig['output_dir'] = $translationDirectory; |
91
|
|
|
$bundleConfig['external_translations_dir'] = $translationDirectory; |
92
|
|
|
$transConfigNew['configs'][mb_strtolower($bundle->getName())] = $bundleConfig; |
93
|
|
|
} |
94
|
|
|
foreach ($this->kernel->getThemes() as $bundle) { |
95
|
|
|
// lets include core themes as they need translation as all other themes, too |
96
|
|
|
// (/system is included in "zikula" config while /themes is not) |
97
|
|
|
/*if (in_array($bundle->getName(), ['ZikulaBootstrapTheme', 'ZikulaAtomTheme', 'ZikulaPrinterTheme', 'ZikulaRssTheme'], true)) { |
98
|
|
|
continue; |
99
|
|
|
}*/ |
100
|
|
|
$bundleConfig = $configTemplate; |
101
|
|
|
$translationDirectory = $bundle->getPath() . '/Resources/translations'; |
102
|
|
|
$bundleConfig['output_dir'] = $translationDirectory; |
103
|
|
|
$bundleConfig['external_translations_dir'] = $translationDirectory; |
104
|
|
|
$transConfigNew['configs'][mb_strtolower($bundle->getName())] = $bundleConfig; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->configDumper->setConfiguration($configName, $transConfigNew); |
109
|
|
|
|
110
|
|
|
$this->cacheClearer->clear('symfony'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|