Skip to content

Commit aadf12a

Browse files
committed
Add french language
1 parent 09a9d14 commit aadf12a

14 files changed

Lines changed: 515 additions & 86 deletions

File tree

app/Http/Controllers/Auth/LogoutController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LogoutController extends Controller
1212
public function __invoke(Request $request)
1313
{
1414
Auth::logout();
15-
$request->session()->invalidate();
15+
// $request->session()->invalidate();
1616
$request->session()->regenerateToken();
1717
return redirect('/');
1818
}

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ class Kernel extends HttpKernel
6464
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6565
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
6666
'can_access_ticket' => \App\Http\Middleware\CanAccessTicket::class,
67+
'set_locale' => \App\Http\Middleware\LocaleMiddleware::class,
6768
];
6869
}

app/Http/Livewire/Auth/Login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function login(): void
9595
]);
9696
}
9797

98+
session()->put('locale', auth()->user()->locale);
9899
redirect()->to(route('home'));
99100

100101
}

app/Http/Livewire/MyNotifications.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function markAllRead(): void
4343
Notification::make()
4444
->success()
4545
->title(__('Notifications updated'))
46-
->body(__('All unread notifications is not marked as read'))
46+
->body(__('All unread notifications is marked as read'))
4747
->send();
4848
}
4949
}

app/Http/Livewire/MyProfile.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Filament\Forms\Components\Grid;
7+
use Filament\Forms\Components\Radio;
78
use Filament\Forms\Components\Select;
89
use Filament\Forms\Components\TextInput;
910
use Filament\Forms\Concerns\InteractsWithForms;
@@ -42,7 +43,8 @@ private function initProfile(): void
4243
$this->user = User::where('id', auth()->user()->id)->first();
4344
$this->form->fill([
4445
'name' => $this->user->name,
45-
'email' => $this->user->email
46+
'email' => $this->user->email,
47+
'locale' => $this->user->locale,
4648
]);
4749
if (session()->has('profile_updated')) {
4850
Notification::make()
@@ -86,6 +88,14 @@ protected function getFormSchema(): array
8688
->label(__('Password confirmation'))
8789
->dehydrated(false),
8890
]),
91+
92+
Grid::make(1)
93+
->schema([
94+
Radio::make('locale')
95+
->label(__('Default language'))
96+
->options(locales())
97+
->required()
98+
]),
8999
];
90100
}
91101

@@ -95,10 +105,12 @@ public function save(): void
95105
if (Hash::check($data['current_password'], $this->user->password)) {
96106
$this->user->name = $data['name'];
97107
$this->user->email = $data['email'];
108+
$this->user->locale = $data['locale'];
98109
if ($data['new_password']) {
99110
$this->user->password = bcrypt($data['new_password']);
100111
}
101112
$this->user->save();
113+
session()->put('locale', $this->user->locale);
102114
session()->flash('profile_updated', true);
103115
redirect()->to(route('my-profile'));
104116
} else {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
8+
class LocaleMiddleware
9+
{
10+
/**
11+
* Handle an incoming request.
12+
*
13+
* @param \Illuminate\Http\Request $request
14+
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
15+
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
16+
*/
17+
public function handle(Request $request, Closure $next)
18+
{
19+
$locale = config('app.locale');
20+
if (session()->has('locale') && in_array(session()->get('locale'), array_keys(config('system.locales')))) {
21+
$locale = session()->get('locale');
22+
} else if (auth()->user()?->locale && in_array(auth()->user()?->locale, array_keys(config('system.locales')))) {
23+
$locale = auth()->user()?->locale;
24+
}
25+
app()->setLocale($locale);
26+
return $next($request);
27+
}
28+
}

app/Models/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class User extends Authenticatable
2929
'password',
3030
'role',
3131
'register_token',
32+
'locale',
3233
];
3334

3435
/**

app/helpers.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,19 @@ function types_list(): array
147147
return $priorities;
148148
}
149149
}
150+
151+
if (!function_exists('locales')) {
152+
/**
153+
* Return application locales as an array of KEY (locale id) => VALUE (locale title)
154+
*
155+
* @return array
156+
*/
157+
function locales(): array
158+
{
159+
$roles = [];
160+
foreach (config('system.locales') as $key => $value) {
161+
$roles[$key] = __($value);
162+
}
163+
return $roles;
164+
}
165+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"require-dev": {
1919
"fakerphp/faker": "^1.9.1",
20+
"kkomelin/laravel-translatable-string-exporter": "^1.17",
2021
"laravel/pint": "^1.0",
2122
"laravel/sail": "^1.0.1",
2223
"mockery/mockery": "^1.4.4",

0 commit comments

Comments
 (0)