Passed
Push — master ( ca1b68...210596 )
by Reza
04:11
created

Manage::getRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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