forked from flarum-lang/spanish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
56 lines (46 loc) · 1.48 KB
/
extend.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
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Settings\Event\Saving;
use Illuminate\Contracts\Container\Container;
$settings = app(SettingsRepositoryInterface::class);
$lang = $settings->get('flarumes.mode');
$mode = empty($lang) ? 'es-ES-informal' : $lang;
return [
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js'),
(new Extend\Event)
->subscribe(SwitchLanguageEvent::class),
(new Flarum\Extend\LanguagePack('/locale/' . $mode . '/'))
];
class SwitchLanguageEvent
{
protected $settings;
protected $container;
public function __construct(SettingsRepositoryInterface $settings, Container $container)
{
$this->settings = $settings;
$this->container = $container;
$this->setLanguage($this->settings->get('flarumes.mode'));
}
public function subscribe($events)
{
$events->listen(Saving::class, [$this, 'handleSaving']);
}
public function handleSaving(Saving $event)
{
$this->setLanguage($this->settings->get('flarumes.mode'));
}
private function setLanguage($lang = null)
{
$mode = empty($lang) ? 'es-ES-informal' : $lang;
new Flarum\Extend\LanguagePack('/locale/' . $mode . '/');
$this->container->make('flarum.locales')->clearCache();
}
}