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
@@ -21,6 +21,7 @@ class UpdateUserRequest extends FormRequest
return [
'bio' => ['sometimes', 'nullable', 'string'],
'height' => ['sometimes', 'nullable', 'integer'],
'locale' => ['sometimes', 'string', Rule::in(config('app.supported_locales', ['fr', 'en']))],
'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'],
'nutritionGoals' => ['sometimes', 'array'],
'nutritionGoals.calories' => ['required_with:nutritionGoals', 'integer', 'min:0', 'max:100000'],
@@ -46,4 +47,20 @@ class UpdateUserRequest extends FormRequest
'nutritionGoals.*.max' => __('api.validation.nutrition_goals_max'),
];
}
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];
}
}