diff --git a/app/Http/Controllers/Users/ProfileController.php b/app/Http/Controllers/Users/ProfileController.php index c1995f0..8fece0f 100644 --- a/app/Http/Controllers/Users/ProfileController.php +++ b/app/Http/Controllers/Users/ProfileController.php @@ -20,7 +20,11 @@ class ProfileController extends Controller public function edit() { - $langList = ['en' => trans('lang.en'), 'id' => trans('lang.id')]; + $langList = [ + 'en' => trans('lang.en'), + 'id' => trans('lang.id'), + 'de' => trans('lang.de'), + ]; return view('users.profile.edit', compact('langList')); } @@ -30,7 +34,7 @@ class ProfileController extends Controller request()->validate([ 'name' => 'required|string|max:100', 'email' => 'required|email|max:255', - 'lang' => 'required|string|in:en,id', + 'lang' => 'required|string|in:en,id,de', ]); $user = auth()->user(); @@ -48,7 +52,7 @@ class ProfileController extends Controller public function switchLang() { $userData = request()->validate([ - 'lang' => 'required|string|in:en,id', + 'lang' => 'required|string|in:en,id,de', ]); $user = request()->user(); diff --git a/resources/lang/en/lang.php b/resources/lang/en/lang.php index b6a1bd1..a3df1f7 100644 --- a/resources/lang/en/lang.php +++ b/resources/lang/en/lang.php @@ -5,4 +5,5 @@ return [ 'switch_tooltip' => 'Switch language to :lang', 'en' => 'English', 'id' => 'Bahasa', + 'de' => 'German', ]; diff --git a/resources/lang/id/lang.php b/resources/lang/id/lang.php index 49af53d..f56cfb4 100644 --- a/resources/lang/id/lang.php +++ b/resources/lang/id/lang.php @@ -3,6 +3,7 @@ return [ 'lang' => 'Bahasa', 'switch_tooltip' => 'Ubah bahasa ke :lang', - 'en' => 'Bahasa Inggris', - 'id' => 'Bahasa Indonesia', + 'en' => 'Inggris', + 'id' => 'Indonesia', + 'de' => 'Jerman', ]; diff --git a/resources/views/layouts/partials/lang-switcher.blade.php b/resources/views/layouts/partials/lang-switcher.blade.php index ebbf247..4269b9e 100644 --- a/resources/views/layouts/partials/lang-switcher.blade.php +++ b/resources/views/layouts/partials/lang-switcher.blade.php @@ -22,4 +22,15 @@ + (auth()->user()->lang == 'id' ? ['disabled' => 'disabled'] : []), ['lang' => 'id'] ) !!} + {!! FormField::formButton( + [ + 'route' => 'users.profile.switch-lang', + 'method' => 'patch', + 'title' => auth()->user()->lang != 'de' ? trans('lang.switch_tooltip', ['lang' => trans('lang.de')]) : '' + ], + 'DE', + ['class' => 'btn btn-default btn-xs', 'de' => 'switch_lang_de'] + + (auth()->user()->lang == 'de' ? ['disabled' => 'disabled'] : []), + ['lang' => 'de'] + ) !!} diff --git a/tests/Feature/Users/UserProfileTest.php b/tests/Feature/Users/UserProfileTest.php index c3e1552..6223d9f 100644 --- a/tests/Feature/Users/UserProfileTest.php +++ b/tests/Feature/Users/UserProfileTest.php @@ -36,7 +36,7 @@ class UserProfileTest extends TestCase $this->submitForm(trans('auth.update_profile'), [ 'name' => 'Nama Saya', 'email' => 'me@domain.com', - 'lang' => 'en', // en, id + 'lang' => 'en', // en, id, de ]); $this->see(trans('auth.profile_updated')); @@ -80,5 +80,10 @@ class UserProfileTest extends TestCase $this->assertEquals('id', app()->getLocale()); $this->assertEquals('id', $user->fresh()->lang); + + $this->submitForm('switch_lang_id', ['lang' => 'de']); + + $this->assertEquals('de', app()->getLocale()); + $this->assertEquals('de', $user->fresh()->lang); } }