-
Notifications
You must be signed in to change notification settings - Fork 0
/
TranslationBundle.php
65 lines (53 loc) · 1.64 KB
/
TranslationBundle.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Pandawa\Bundle\TranslationBundle;
use Illuminate\Translation\TranslationServiceProvider;
use Illuminate\Translation\Translator;
use Pandawa\Bundle\FoundationBundle\Plugin\RegisterBundlesPlugin;
use Pandawa\Component\Foundation\Bundle\Bundle;
use Pandawa\Component\Foundation\ResourcePublisher;
use Pandawa\Contracts\Foundation\HasPluginInterface;
/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
class TranslationBundle extends Bundle implements HasPluginInterface
{
public function register(): void
{
$this->app->instance('path.lang', $this->app->basePath('resources/trans'));
}
public function configure(): void
{
ResourcePublisher::publishes(
static::class,
$this->getPaths(['auth.php', 'pagination.php', 'passwords.php', 'validation.php']),
['default-lang', 'lang']
);
}
public function plugins(): array
{
return [
new RegisterBundlesPlugin([TranslationServiceProvider::class]),
];
}
protected function translator(): Translator
{
return $this->app['translator'];
}
protected function getPaths(array $files): array
{
$paths = [];
foreach ($files as $file) {
$paths[$this->getBundleLangPath($file)] = $this->getAppLangPath($file);
}
return $paths;
}
protected function getBundleLangPath(string $file): string
{
return $this->getPath('Resources/trans/en/' . $file);
}
protected function getAppLangPath(string $file): string
{
return $this->app['path.lang'] . '/en/' . $file;
}
}