feat: locale

This commit is contained in:
2026-05-21 21:32:20 +02:00
parent 19e65e36f3
commit 8e5a50dd2b
21 changed files with 337 additions and 32 deletions
+17
View File
@@ -37,6 +37,7 @@ class RegisterRequest extends FormRequest
'unique:users,name',
],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'locale' => ['sometimes', 'string', Rule::in(config('app.supported_locales', ['fr', 'en']))],
'password' => ['required', 'string', 'min:8'],
'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'],
'bio' => ['nullable', 'string'],
@@ -56,4 +57,20 @@ class RegisterRequest extends FormRequest
'avatar.max' => __('api.validation.image_max_2mb'),
];
}
protected function prepareForValidation(): void
{
if ($this->has('locale')) {
$this->merge([
'locale' => $this->normalizeLocale((string) $this->input('locale')),
]);
}
}
private function normalizeLocale(string $locale): string
{
$locale = strtolower(str_replace('_', '-', $locale));
return explode('-', $locale)[0];
}
}