-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.php
36 lines (30 loc) · 1.14 KB
/
hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
use Kirby\Data\Json;
use Kirby\Filesystem\Dir;
use Kirby\Filesystem\F;
return [
'system.loadPlugins:after' => function () {
$contentRoot = kirby()->root('content');
$path = $contentRoot.DS.'localizer';
$files = Dir::read($path);
$translations = [];
foreach ($files as $file) {
$filePath = $path.DS.$file;
if (!F::exists($filePath)) {
return;
}
$content = Json::read($filePath);
if (F::is($file, 'json')) {
if (is_array($content['translations']) && count($content['translations']) > 0) {
$translations[$content['language']['id']] = array_map(function ($arr) {
if (array_key_exists('override', $arr) && $arr['override']) {
return [$arr['key'] => $arr['override']];
}
return $arr;
}, $content['translations'])[0];
}
}
}
kirby()->extend(['translations' => $translations], kirby()->plugin('gearsdigital/kirby-panel-localizer'));
},
];