Manage::updatedSelectedLang()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace EasyPanel\Http\Livewire\Translation;
4
5
use Livewire\Component;
6
use Illuminate\Support\Facades\File;
7
use EasyPanel\Support\Contract\LangManager;
8
9
class Manage extends Component
10
{
11
    public $selectedLang;
12
    public $texts;
13
    public $language;
14
15
    public function mount()
16
    {
17
        $this->selectedLang = (config('easy_panel.lang') ?? 'en').'_panel';
18
        $this->texts = LangManager::getTexts($this->selectedLang);
19
    }
20
21
    public function updatedSelectedLang($value)
22
    {
23
        $this->texts = LangManager::getTexts($value);
24
    }
25
26
    public function render()
27
    {
28
        return view('admin::livewire.translation.manage')
29
            ->layout('admin::layouts.app', ['title' => __('Translation')]);
30
    }
31
32
    protected function getRules()
33
    {
34
        return [
35
            'language' => 'required|min:2|max:10|string'
36
        ];
37
    }
38
39
    public function create()
40
    {
41
        $this->validate();
42
        try {
43
            $lang = strtolower($this->language) . '_panel';
44
            File::copy(LangManager::getPath('en_panel'), LangManager::getPath($lang));
45
46
            $this->dispatchBrowserEvent('show-message', ['type' => 'success', 'message' => __('CreatedMessage', ['name' => __('Translation') ])]);
47
        } catch (\Exception $exception){
48
            $this->dispatchBrowserEvent('show-message', ['type' => 'error', 'message' => $exception->getMessage()]);
49
        }
50
51
        $this->reset('language');
52
    }
53
54
    public function update()
55
    {
56
        LangManager::updateLanguage($this->selectedLang, $this->texts);
57
58
        $this->dispatchBrowserEvent('show-message', ['type' => 'success', 'message' => __('UpdatedMessage', ['name' => __('Translation') ])]);
59
    }
60
}
61