From bcc067ec67a2ca8bd5ad66de28675465150008fb Mon Sep 17 00:00:00 2001 From: Leon Morival Date: Wed, 20 May 2026 20:54:41 +0200 Subject: [PATCH] feat: translations --- .env.example | 2 +- app/Http/Controllers/AuthController.php | 33 +-- .../Controllers/DeviceTokenController.php | 6 +- .../MealImageAnalysisController.php | 2 +- .../Controllers/PostReviewsController.php | 2 +- app/Http/Controllers/StravaController.php | 8 +- app/Http/Middleware/EnsureEmailIsVerified.php | 31 +++ .../Requests/MealImageAnalysisRequest.php | 6 +- app/Http/Requests/MealPostCalendarRequest.php | 2 +- app/Http/Requests/MealPostsRequest.php | 6 +- app/Http/Requests/RegisterRequest.php | 2 +- app/Http/Requests/UpdateUserRequest.php | 10 +- app/Notifications/TestNotification.php | 4 +- bootstrap/app.php | 26 ++- config/app.php | 2 +- lang/en/api.php | 50 ++++ lang/en/auth.php | 20 ++ lang/en/pagination.php | 19 ++ lang/en/passwords.php | 22 ++ lang/en/validation.php | 200 ++++++++++++++++ lang/fr/api.php | 50 ++++ lang/fr/auth.php | 7 + lang/fr/pagination.php | 6 + lang/fr/passwords.php | 9 + lang/fr/validation.php | 213 ++++++++++++++++++ tests/Feature/AccountDeletionTest.php | 2 +- tests/Feature/EmailVerificationTest.php | 6 +- tests/Feature/PostReviewsControllerTest.php | 2 +- tests/Feature/StravaConnectionTest.php | 2 +- 29 files changed, 703 insertions(+), 47 deletions(-) create mode 100644 app/Http/Middleware/EnsureEmailIsVerified.php create mode 100644 lang/en/api.php create mode 100644 lang/en/auth.php create mode 100644 lang/en/pagination.php create mode 100644 lang/en/passwords.php create mode 100644 lang/en/validation.php create mode 100644 lang/fr/api.php create mode 100644 lang/fr/auth.php create mode 100644 lang/fr/pagination.php create mode 100644 lang/fr/passwords.php create mode 100644 lang/fr/validation.php diff --git a/.env.example b/.env.example index e86e313..fbb5c45 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ APP_KEY= APP_DEBUG=true APP_URL=http://localhost APP_PORT=8003 -APP_LOCALE=en +APP_LOCALE=fr APP_FALLBACK_LOCALE=en APP_FAKER_LOCALE=en_US diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 1a1b046..c06a4ab 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -40,7 +40,7 @@ class AuthController extends Controller $token = $user->createToken('api', ['user'])->plainTextToken; return response()->json([ - 'message' => 'Compte créé. Consulte tes emails pour le vérifier.', + 'message' => __('api.auth.registered_unverified'), 'user' => new UserResource($user), ], 201)->cookie('token', $token, 60 * 24 * 30); } @@ -53,13 +53,13 @@ class AuthController extends Controller if (! $user || ! Hash::check($data['password'], $user->password)) { return response()->json([ - 'message' => 'Identifiants invalides', + 'message' => __('api.auth.invalid_credentials'), ], 401); } if (! $user->hasVerifiedEmail()) { return response()->json([ - 'message' => 'Vérifie ton adresse email avant de te connecter.', + 'message' => __('api.auth.email_not_verified'), ], 403); } @@ -74,10 +74,15 @@ class AuthController extends Controller { $user = User::findOrFail($id); - abort_unless( - hash_equals($hash, sha1($user->getEmailForVerification())), - 403 - ); + if (! hash_equals($hash, sha1($user->getEmailForVerification()))) { + if ($request->expectsJson()) { + return response()->json([ + 'message' => __('api.auth.invalid_verification_link'), + ], 403); + } + + abort(403, __('api.auth.invalid_verification_link')); + } $alreadyVerified = $user->hasVerifiedEmail(); @@ -90,8 +95,8 @@ class AuthController extends Controller if ($request->expectsJson()) { return response()->json([ 'message' => $alreadyVerified - ? 'Compte déjà vérifié.' - : 'Compte vérifié avec succès.', + ? __('api.auth.already_verified') + : __('api.auth.verified'), 'user' => new UserResource($user->fresh()), ]); } @@ -108,14 +113,14 @@ class AuthController extends Controller if ($user->hasVerifiedEmail()) { return response()->json([ - 'message' => 'Compte déjà vérifié.', + 'message' => __('api.auth.already_verified'), ]); } $user->sendEmailVerificationNotification(); return response()->json([ - 'message' => 'Email de vérification envoyé.', + 'message' => __('api.auth.verification_sent'), ]); } @@ -125,7 +130,7 @@ class AuthController extends Controller $request->user()->currentAccessToken()->delete(); return response()->json([ - 'message' => 'Déconnecté avec succès', + 'message' => __('api.auth.logout'), ])->withoutCookie('token'); } @@ -134,7 +139,7 @@ class AuthController extends Controller $user = auth()->user(); if (! $user) { - return response()->json(['message' => 'Non authentifié'], 401); + return response()->json(['message' => __('api.auth.unauthenticated')], 401); } return new UserResource($user); @@ -201,7 +206,7 @@ class AuthController extends Controller } return response()->json([ - 'message' => 'Compte supprimé avec succès', + 'message' => __('api.auth.deleted'), ])->withoutCookie('token'); } diff --git a/app/Http/Controllers/DeviceTokenController.php b/app/Http/Controllers/DeviceTokenController.php index 854ab40..35b5194 100644 --- a/app/Http/Controllers/DeviceTokenController.php +++ b/app/Http/Controllers/DeviceTokenController.php @@ -25,8 +25,8 @@ class DeviceTokenController extends Controller return response()->json([ 'message' => $deviceToken->wasRecentlyCreated - ? 'Token appareil enregistré.' - : 'Token appareil mis à jour.', + ? __('api.device_tokens.created') + : __('api.device_tokens.updated'), 'deviceToken' => [ 'id' => $deviceToken->id, 'expoPushToken' => $deviceToken->expo_push_token, @@ -40,7 +40,7 @@ class DeviceTokenController extends Controller auth()->user()->notify(new TestNotification); return response()->json([ - 'message' => 'Notification envoyée', + 'message' => __('api.device_tokens.notification_sent'), ]); } diff --git a/app/Http/Controllers/MealImageAnalysisController.php b/app/Http/Controllers/MealImageAnalysisController.php index 2e43fcf..aae67d4 100644 --- a/app/Http/Controllers/MealImageAnalysisController.php +++ b/app/Http/Controllers/MealImageAnalysisController.php @@ -25,7 +25,7 @@ class MealImageAnalysisController extends Controller report($exception); return response()->json([ - 'message' => "Impossible d'analyser l'image pour le moment.", + 'message' => __('api.meal_image_analysis.failed'), ], 502); } diff --git a/app/Http/Controllers/PostReviewsController.php b/app/Http/Controllers/PostReviewsController.php index 782f14d..390bb80 100644 --- a/app/Http/Controllers/PostReviewsController.php +++ b/app/Http/Controllers/PostReviewsController.php @@ -36,7 +36,7 @@ class PostReviewsController extends Controller ->where('user_id', $userId) ->exists(), 409, - 'Vous avez déjà donné un avis pour ce repas.' + __('api.post_reviews.already_exists') ); $postReview = PostReviews::create([ diff --git a/app/Http/Controllers/StravaController.php b/app/Http/Controllers/StravaController.php index 9dead08..608199f 100644 --- a/app/Http/Controllers/StravaController.php +++ b/app/Http/Controllers/StravaController.php @@ -50,13 +50,13 @@ class StravaController extends Controller if (! is_array($state) || $state['user_id'] !== $request->user()->getKey()) { return response()->json([ - 'message' => 'La connexion Strava a expiré. Relance la connexion.', + 'message' => __('api.strava.state_expired'), ], 422); } if (isset($data['error'])) { return response()->json([ - 'message' => 'Connexion Strava refusée.', + 'message' => __('api.strava.refused'), ], 422); } @@ -102,13 +102,13 @@ class StravaController extends Controller if (! $connection) { return response()->json([ - 'message' => 'Connecte Strava avant de synchroniser tes workouts.', + 'message' => __('api.strava.missing_connection'), ], 422); } if (! $this->canReadActivities($connection->scopes ?? [])) { return response()->json([ - 'message' => 'La connexion Strava doit autoriser le scope activity:read ou activity:read_all.', + 'message' => __('api.strava.missing_activity_scope'), ], 422); } diff --git a/app/Http/Middleware/EnsureEmailIsVerified.php b/app/Http/Middleware/EnsureEmailIsVerified.php new file mode 100644 index 0000000..8376595 --- /dev/null +++ b/app/Http/Middleware/EnsureEmailIsVerified.php @@ -0,0 +1,31 @@ +user() || + ($request->user() instanceof MustVerifyEmail && + ! $request->user()->hasVerifiedEmail())) { + return $request->expectsJson() + ? abort(403, __('api.auth.email_not_verified')) + : Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice')); + } + + return $next($request); + } +} diff --git a/app/Http/Requests/MealImageAnalysisRequest.php b/app/Http/Requests/MealImageAnalysisRequest.php index 99c2a85..256e631 100644 --- a/app/Http/Requests/MealImageAnalysisRequest.php +++ b/app/Http/Requests/MealImageAnalysisRequest.php @@ -21,9 +21,9 @@ class MealImageAnalysisRequest extends FormRequest public function messages(): array { return [ - 'image.required' => 'Ajoute une image à analyser.', - 'image.image' => 'Le fichier doit être une image.', - 'image.max' => "L'image ne doit pas dépasser 4 Mo.", + 'image.required' => __('api.validation.image_required'), + 'image.image' => __('api.validation.image_file'), + 'image.max' => __('api.validation.image_max_4mb'), ]; } } diff --git a/app/Http/Requests/MealPostCalendarRequest.php b/app/Http/Requests/MealPostCalendarRequest.php index 9b4165d..d4e1230 100644 --- a/app/Http/Requests/MealPostCalendarRequest.php +++ b/app/Http/Requests/MealPostCalendarRequest.php @@ -21,7 +21,7 @@ class MealPostCalendarRequest extends FormRequest public function messages(): array { return [ - 'month.date_format' => 'Choisis un mois valide.', + 'month.date_format' => __('api.validation.month_valid'), ]; } } diff --git a/app/Http/Requests/MealPostsRequest.php b/app/Http/Requests/MealPostsRequest.php index 45e84de..3ebb629 100644 --- a/app/Http/Requests/MealPostsRequest.php +++ b/app/Http/Requests/MealPostsRequest.php @@ -45,9 +45,9 @@ class MealPostsRequest extends FormRequest public function messages(): array { return [ - 'image.max' => "L'image ne doit pas dépasser 4 Mo.", - 'image_url.required_without' => 'Ajoute une image au repas.', - 'visibility' => 'Choisis une visibilité valide.', + 'image.max' => __('api.validation.image_max_4mb'), + 'image_url.required_without' => __('api.validation.meal_image_required'), + 'visibility' => __('api.validation.visibility_valid'), ]; } } diff --git a/app/Http/Requests/RegisterRequest.php b/app/Http/Requests/RegisterRequest.php index 52859e4..be0867e 100644 --- a/app/Http/Requests/RegisterRequest.php +++ b/app/Http/Requests/RegisterRequest.php @@ -35,7 +35,7 @@ class RegisterRequest extends FormRequest public function messages(): array { return [ - 'avatar.max' => "L'image ne doit pas dépasser 2 Mo.", + 'avatar.max' => __('api.validation.image_max_2mb'), ]; } } diff --git a/app/Http/Requests/UpdateUserRequest.php b/app/Http/Requests/UpdateUserRequest.php index b356960..b53b6de 100644 --- a/app/Http/Requests/UpdateUserRequest.php +++ b/app/Http/Requests/UpdateUserRequest.php @@ -29,11 +29,11 @@ class UpdateUserRequest extends FormRequest public function messages(): array { return [ - 'avatar.max' => "L'image ne doit pas dépasser 2 Mo.", - 'nutritionGoals.calories.integer' => 'Les calories doivent etre un nombre entier.', - 'nutritionGoals.*.required_with' => 'Renseigne tous les objectifs nutritionnels.', - 'nutritionGoals.*.min' => 'Les objectifs nutritionnels doivent etre positifs.', - 'nutritionGoals.*.max' => 'La valeur de cet objectif nutritionnel est trop elevee.', + 'avatar.max' => __('api.validation.image_max_2mb'), + 'nutritionGoals.calories.integer' => __('api.validation.calories_integer'), + 'nutritionGoals.*.required_with' => __('api.validation.nutrition_goals_required'), + 'nutritionGoals.*.min' => __('api.validation.nutrition_goals_positive'), + 'nutritionGoals.*.max' => __('api.validation.nutrition_goals_max'), ]; } } diff --git a/app/Notifications/TestNotification.php b/app/Notifications/TestNotification.php index 36a95f6..df335ad 100644 --- a/app/Notifications/TestNotification.php +++ b/app/Notifications/TestNotification.php @@ -42,8 +42,8 @@ class TestNotification extends Notification public function toExpoPush($notifiable) { return [ - 'title' => 'Test', - 'body' => 'Notification test depuis Laravel API', + 'title' => __('api.notifications.test_title'), + 'body' => __('api.notifications.test_body'), 'data' => ['test' => true], ]; } diff --git a/bootstrap/app.php b/bootstrap/app.php index 9db2488..3384821 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,8 +1,11 @@ withRouting( @@ -13,7 +16,28 @@ return Application::configure(basePath: dirname(__DIR__)) ) ->withMiddleware(function (Middleware $middleware): void { $middleware->prepend(\App\Http\Middleware\AuthenticateWithCookie::class); + $middleware->alias([ + 'verified' => \App\Http\Middleware\EnsureEmailIsVerified::class, + ]); }) ->withExceptions(function (Exceptions $exceptions): void { - // + $exceptions->render(function (AuthenticationException $exception, Request $request) { + if (! $request->expectsJson()) { + return null; + } + + return response()->json([ + 'message' => __('api.auth.unauthenticated'), + ], 401); + }); + + $exceptions->render(function (InvalidSignatureException $exception, Request $request) { + if (! $request->expectsJson()) { + return null; + } + + return response()->json([ + 'message' => __('api.auth.invalid_verification_link'), + ], 403); + }); })->create(); diff --git a/config/app.php b/config/app.php index 423eed5..94faa30 100644 --- a/config/app.php +++ b/config/app.php @@ -78,7 +78,7 @@ return [ | */ - 'locale' => env('APP_LOCALE', 'en'), + 'locale' => env('APP_LOCALE', 'fr'), 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), diff --git a/lang/en/api.php b/lang/en/api.php new file mode 100644 index 0000000..ecc1bc5 --- /dev/null +++ b/lang/en/api.php @@ -0,0 +1,50 @@ + [ + 'registered_unverified' => 'Account created. Check your email to verify it.', + 'invalid_credentials' => 'Invalid credentials.', + 'email_not_verified' => 'Verify your email address before signing in.', + 'already_verified' => 'Account already verified.', + 'verified' => 'Account verified successfully.', + 'verification_sent' => 'Verification email sent.', + 'logout' => 'Logged out successfully.', + 'unauthenticated' => 'Unauthenticated.', + 'deleted' => 'Account deleted successfully.', + 'invalid_verification_link' => 'This verification link is invalid or has expired.', + ], + 'device_tokens' => [ + 'created' => 'Device token registered.', + 'updated' => 'Device token updated.', + 'notification_sent' => 'Notification sent.', + ], + 'meal_image_analysis' => [ + 'failed' => 'Unable to analyze the image right now.', + ], + 'notifications' => [ + 'test_title' => 'Test', + 'test_body' => 'Test notification from the Laravel API.', + ], + 'post_reviews' => [ + 'already_exists' => 'You have already reviewed this meal.', + ], + 'strava' => [ + 'state_expired' => 'The Strava connection has expired. Start the connection again.', + 'refused' => 'Strava connection refused.', + 'missing_connection' => 'Connect Strava before syncing your workouts.', + 'missing_activity_scope' => 'The Strava connection must allow the activity:read or activity:read_all scope.', + ], + 'validation' => [ + 'image_required' => 'Add an image to analyze.', + 'image_file' => 'The file must be an image.', + 'image_max_2mb' => 'The image must not be greater than 2 MB.', + 'image_max_4mb' => 'The image must not be greater than 4 MB.', + 'meal_image_required' => 'Add an image to the meal.', + 'visibility_valid' => 'Choose a valid visibility.', + 'month_valid' => 'Choose a valid month.', + 'calories_integer' => 'Calories must be an integer.', + 'nutrition_goals_required' => 'Fill in all nutrition goals.', + 'nutrition_goals_positive' => 'Nutrition goals must be positive.', + 'nutrition_goals_max' => 'This nutrition goal value is too high.', + ], +]; diff --git a/lang/en/auth.php b/lang/en/auth.php new file mode 100644 index 0000000..6598e2c --- /dev/null +++ b/lang/en/auth.php @@ -0,0 +1,20 @@ + 'These credentials do not match our records.', + 'password' => 'The provided password is incorrect.', + 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', + +]; diff --git a/lang/en/pagination.php b/lang/en/pagination.php new file mode 100644 index 0000000..d481411 --- /dev/null +++ b/lang/en/pagination.php @@ -0,0 +1,19 @@ + '« Previous', + 'next' => 'Next »', + +]; diff --git a/lang/en/passwords.php b/lang/en/passwords.php new file mode 100644 index 0000000..fad3a7d --- /dev/null +++ b/lang/en/passwords.php @@ -0,0 +1,22 @@ + 'Your password has been reset.', + 'sent' => 'We have emailed your password reset link.', + 'throttled' => 'Please wait before retrying.', + 'token' => 'This password reset token is invalid.', + 'user' => "We can't find a user with that email address.", + +]; diff --git a/lang/en/validation.php b/lang/en/validation.php new file mode 100644 index 0000000..63ec29a --- /dev/null +++ b/lang/en/validation.php @@ -0,0 +1,200 @@ + 'The :attribute field must be accepted.', + 'accepted_if' => 'The :attribute field must be accepted when :other is :value.', + 'active_url' => 'The :attribute field must be a valid URL.', + 'after' => 'The :attribute field must be a date after :date.', + 'after_or_equal' => 'The :attribute field must be a date after or equal to :date.', + 'alpha' => 'The :attribute field must only contain letters.', + 'alpha_dash' => 'The :attribute field must only contain letters, numbers, dashes, and underscores.', + 'alpha_num' => 'The :attribute field must only contain letters and numbers.', + 'any_of' => 'The :attribute field is invalid.', + 'array' => 'The :attribute field must be an array.', + 'ascii' => 'The :attribute field must only contain single-byte alphanumeric characters and symbols.', + 'before' => 'The :attribute field must be a date before :date.', + 'before_or_equal' => 'The :attribute field must be a date before or equal to :date.', + 'between' => [ + 'array' => 'The :attribute field must have between :min and :max items.', + 'file' => 'The :attribute field must be between :min and :max kilobytes.', + 'numeric' => 'The :attribute field must be between :min and :max.', + 'string' => 'The :attribute field must be between :min and :max characters.', + ], + 'boolean' => 'The :attribute field must be true or false.', + 'can' => 'The :attribute field contains an unauthorized value.', + 'confirmed' => 'The :attribute field confirmation does not match.', + 'contains' => 'The :attribute field is missing a required value.', + 'current_password' => 'The password is incorrect.', + 'date' => 'The :attribute field must be a valid date.', + 'date_equals' => 'The :attribute field must be a date equal to :date.', + 'date_format' => 'The :attribute field must match the format :format.', + 'decimal' => 'The :attribute field must have :decimal decimal places.', + 'declined' => 'The :attribute field must be declined.', + 'declined_if' => 'The :attribute field must be declined when :other is :value.', + 'different' => 'The :attribute field and :other must be different.', + 'digits' => 'The :attribute field must be :digits digits.', + 'digits_between' => 'The :attribute field must be between :min and :max digits.', + 'dimensions' => 'The :attribute field has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'doesnt_contain' => 'The :attribute field must not contain any of the following: :values.', + 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', + 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', + 'email' => 'The :attribute field must be a valid email address.', + 'encoding' => 'The :attribute field must be encoded in :encoding.', + 'ends_with' => 'The :attribute field must end with one of the following: :values.', + 'enum' => 'The selected :attribute is invalid.', + 'exists' => 'The selected :attribute is invalid.', + 'extensions' => 'The :attribute field must have one of the following extensions: :values.', + 'file' => 'The :attribute field must be a file.', + 'filled' => 'The :attribute field must have a value.', + 'gt' => [ + 'array' => 'The :attribute field must have more than :value items.', + 'file' => 'The :attribute field must be greater than :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than :value.', + 'string' => 'The :attribute field must be greater than :value characters.', + ], + 'gte' => [ + 'array' => 'The :attribute field must have :value items or more.', + 'file' => 'The :attribute field must be greater than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than or equal to :value.', + 'string' => 'The :attribute field must be greater than or equal to :value characters.', + ], + 'hex_color' => 'The :attribute field must be a valid hexadecimal color.', + 'image' => 'The :attribute field must be an image.', + 'in' => 'The selected :attribute is invalid.', + 'in_array' => 'The :attribute field must exist in :other.', + 'in_array_keys' => 'The :attribute field must contain at least one of the following keys: :values.', + 'integer' => 'The :attribute field must be an integer.', + 'ip' => 'The :attribute field must be a valid IP address.', + 'ipv4' => 'The :attribute field must be a valid IPv4 address.', + 'ipv6' => 'The :attribute field must be a valid IPv6 address.', + 'json' => 'The :attribute field must be a valid JSON string.', + 'list' => 'The :attribute field must be a list.', + 'lowercase' => 'The :attribute field must be lowercase.', + 'lt' => [ + 'array' => 'The :attribute field must have less than :value items.', + 'file' => 'The :attribute field must be less than :value kilobytes.', + 'numeric' => 'The :attribute field must be less than :value.', + 'string' => 'The :attribute field must be less than :value characters.', + ], + 'lte' => [ + 'array' => 'The :attribute field must not have more than :value items.', + 'file' => 'The :attribute field must be less than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be less than or equal to :value.', + 'string' => 'The :attribute field must be less than or equal to :value characters.', + ], + 'mac_address' => 'The :attribute field must be a valid MAC address.', + 'max' => [ + 'array' => 'The :attribute field must not have more than :max items.', + 'file' => 'The :attribute field must not be greater than :max kilobytes.', + 'numeric' => 'The :attribute field must not be greater than :max.', + 'string' => 'The :attribute field must not be greater than :max characters.', + ], + 'max_digits' => 'The :attribute field must not have more than :max digits.', + 'mimes' => 'The :attribute field must be a file of type: :values.', + 'mimetypes' => 'The :attribute field must be a file of type: :values.', + 'min' => [ + 'array' => 'The :attribute field must have at least :min items.', + 'file' => 'The :attribute field must be at least :min kilobytes.', + 'numeric' => 'The :attribute field must be at least :min.', + 'string' => 'The :attribute field must be at least :min characters.', + ], + 'min_digits' => 'The :attribute field must have at least :min digits.', + 'missing' => 'The :attribute field must be missing.', + 'missing_if' => 'The :attribute field must be missing when :other is :value.', + 'missing_unless' => 'The :attribute field must be missing unless :other is :value.', + 'missing_with' => 'The :attribute field must be missing when :values is present.', + 'missing_with_all' => 'The :attribute field must be missing when :values are present.', + 'multiple_of' => 'The :attribute field must be a multiple of :value.', + 'not_in' => 'The selected :attribute is invalid.', + 'not_regex' => 'The :attribute field format is invalid.', + 'numeric' => 'The :attribute field must be a number.', + 'password' => [ + 'letters' => 'The :attribute field must contain at least one letter.', + 'mixed' => 'The :attribute field must contain at least one uppercase and one lowercase letter.', + 'numbers' => 'The :attribute field must contain at least one number.', + 'symbols' => 'The :attribute field must contain at least one symbol.', + 'uncompromised' => 'The given :attribute has appeared in a data leak. Please choose a different :attribute.', + ], + 'present' => 'The :attribute field must be present.', + 'present_if' => 'The :attribute field must be present when :other is :value.', + 'present_unless' => 'The :attribute field must be present unless :other is :value.', + 'present_with' => 'The :attribute field must be present when :values is present.', + 'present_with_all' => 'The :attribute field must be present when :values are present.', + 'prohibited' => 'The :attribute field is prohibited.', + 'prohibited_if' => 'The :attribute field is prohibited when :other is :value.', + 'prohibited_if_accepted' => 'The :attribute field is prohibited when :other is accepted.', + 'prohibited_if_declined' => 'The :attribute field is prohibited when :other is declined.', + 'prohibited_unless' => 'The :attribute field is prohibited unless :other is in :values.', + 'prohibits' => 'The :attribute field prohibits :other from being present.', + 'regex' => 'The :attribute field format is invalid.', + 'required' => 'The :attribute field is required.', + 'required_array_keys' => 'The :attribute field must contain entries for: :values.', + 'required_if' => 'The :attribute field is required when :other is :value.', + 'required_if_accepted' => 'The :attribute field is required when :other is accepted.', + 'required_if_declined' => 'The :attribute field is required when :other is declined.', + 'required_unless' => 'The :attribute field is required unless :other is in :values.', + 'required_with' => 'The :attribute field is required when :values is present.', + 'required_with_all' => 'The :attribute field is required when :values are present.', + 'required_without' => 'The :attribute field is required when :values is not present.', + 'required_without_all' => 'The :attribute field is required when none of :values are present.', + 'same' => 'The :attribute field must match :other.', + 'size' => [ + 'array' => 'The :attribute field must contain :size items.', + 'file' => 'The :attribute field must be :size kilobytes.', + 'numeric' => 'The :attribute field must be :size.', + 'string' => 'The :attribute field must be :size characters.', + ], + 'starts_with' => 'The :attribute field must start with one of the following: :values.', + 'string' => 'The :attribute field must be a string.', + 'timezone' => 'The :attribute field must be a valid timezone.', + 'unique' => 'The :attribute has already been taken.', + 'uploaded' => 'The :attribute failed to upload.', + 'uppercase' => 'The :attribute field must be uppercase.', + 'url' => 'The :attribute field must be a valid URL.', + 'ulid' => 'The :attribute field must be a valid ULID.', + 'uuid' => 'The :attribute field must be a valid UUID.', + + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap our attribute placeholder + | with something more reader friendly such as "E-Mail Address" instead + | of "email". This simply helps us make our message more expressive. + | + */ + + 'attributes' => [], + +]; diff --git a/lang/fr/api.php b/lang/fr/api.php new file mode 100644 index 0000000..455147d --- /dev/null +++ b/lang/fr/api.php @@ -0,0 +1,50 @@ + [ + 'registered_unverified' => 'Compte créé. Consulte tes emails pour le vérifier.', + 'invalid_credentials' => 'Identifiants invalides.', + 'email_not_verified' => 'Vérifie ton adresse email avant de te connecter.', + 'already_verified' => 'Compte déjà vérifié.', + 'verified' => 'Compte vérifié avec succès.', + 'verification_sent' => 'Email de vérification envoyé.', + 'logout' => 'Déconnecté avec succès.', + 'unauthenticated' => 'Non authentifié.', + 'deleted' => 'Compte supprimé avec succès.', + 'invalid_verification_link' => 'Ce lien de vérification est invalide ou a expiré.', + ], + 'device_tokens' => [ + 'created' => 'Token appareil enregistré.', + 'updated' => 'Token appareil mis à jour.', + 'notification_sent' => 'Notification envoyée.', + ], + 'meal_image_analysis' => [ + 'failed' => "Impossible d'analyser l'image pour le moment.", + ], + 'notifications' => [ + 'test_title' => 'Test', + 'test_body' => 'Notification test depuis Laravel API.', + ], + 'post_reviews' => [ + 'already_exists' => 'Vous avez déjà donné un avis pour ce repas.', + ], + 'strava' => [ + 'state_expired' => 'La connexion Strava a expiré. Relance la connexion.', + 'refused' => 'Connexion Strava refusée.', + 'missing_connection' => 'Connecte Strava avant de synchroniser tes workouts.', + 'missing_activity_scope' => 'La connexion Strava doit autoriser le scope activity:read ou activity:read_all.', + ], + 'validation' => [ + 'image_required' => 'Ajoute une image à analyser.', + 'image_file' => 'Le fichier doit être une image.', + 'image_max_2mb' => "L'image ne doit pas dépasser 2 Mo.", + 'image_max_4mb' => "L'image ne doit pas dépasser 4 Mo.", + 'meal_image_required' => 'Ajoute une image au repas.', + 'visibility_valid' => 'Choisis une visibilité valide.', + 'month_valid' => 'Choisis un mois valide.', + 'calories_integer' => 'Les calories doivent être un nombre entier.', + 'nutrition_goals_required' => 'Renseigne tous les objectifs nutritionnels.', + 'nutrition_goals_positive' => 'Les objectifs nutritionnels doivent être positifs.', + 'nutrition_goals_max' => 'La valeur de cet objectif nutritionnel est trop élevée.', + ], +]; diff --git a/lang/fr/auth.php b/lang/fr/auth.php new file mode 100644 index 0000000..a18a165 --- /dev/null +++ b/lang/fr/auth.php @@ -0,0 +1,7 @@ + 'Ces identifiants ne correspondent pas à nos enregistrements.', + 'password' => 'Le mot de passe fourni est incorrect.', + 'throttle' => 'Trop de tentatives de connexion. Veuillez réessayer dans :seconds secondes.', +]; diff --git a/lang/fr/pagination.php b/lang/fr/pagination.php new file mode 100644 index 0000000..57f25ff --- /dev/null +++ b/lang/fr/pagination.php @@ -0,0 +1,6 @@ + '« Précédent', + 'next' => 'Suivant »', +]; diff --git a/lang/fr/passwords.php b/lang/fr/passwords.php new file mode 100644 index 0000000..b9956cd --- /dev/null +++ b/lang/fr/passwords.php @@ -0,0 +1,9 @@ + 'Votre mot de passe a été réinitialisé.', + 'sent' => 'Nous vous avons envoyé le lien de réinitialisation du mot de passe.', + 'throttled' => 'Veuillez patienter avant de réessayer.', + 'token' => 'Ce jeton de réinitialisation du mot de passe est invalide.', + 'user' => 'Nous ne trouvons aucun utilisateur avec cette adresse email.', +]; diff --git a/lang/fr/validation.php b/lang/fr/validation.php new file mode 100644 index 0000000..1ac404c --- /dev/null +++ b/lang/fr/validation.php @@ -0,0 +1,213 @@ + 'Le champ :attribute doit être accepté.', + 'accepted_if' => 'Le champ :attribute doit être accepté lorsque :other vaut :value.', + 'active_url' => 'Le champ :attribute doit être une URL valide.', + 'after' => 'Le champ :attribute doit être une date postérieure à :date.', + 'after_or_equal' => 'Le champ :attribute doit être une date postérieure ou égale à :date.', + 'alpha' => 'Le champ :attribute ne doit contenir que des lettres.', + 'alpha_dash' => 'Le champ :attribute ne doit contenir que des lettres, des chiffres, des tirets et des underscores.', + 'alpha_num' => 'Le champ :attribute ne doit contenir que des lettres et des chiffres.', + 'any_of' => 'Le champ :attribute est invalide.', + 'array' => 'Le champ :attribute doit être un tableau.', + 'ascii' => 'Le champ :attribute ne doit contenir que des caractères alphanumériques et symboles mono-octets.', + 'before' => 'Le champ :attribute doit être une date antérieure à :date.', + 'before_or_equal' => 'Le champ :attribute doit être une date antérieure ou égale à :date.', + 'between' => [ + 'array' => 'Le champ :attribute doit contenir entre :min et :max éléments.', + 'file' => 'Le fichier :attribute doit peser entre :min et :max kilo-octets.', + 'numeric' => 'Le champ :attribute doit être compris entre :min et :max.', + 'string' => 'Le champ :attribute doit contenir entre :min et :max caractères.', + ], + 'boolean' => 'Le champ :attribute doit être vrai ou faux.', + 'can' => 'Le champ :attribute contient une valeur non autorisée.', + 'confirmed' => 'La confirmation du champ :attribute ne correspond pas.', + 'contains' => 'Le champ :attribute ne contient pas une valeur requise.', + 'current_password' => 'Le mot de passe est incorrect.', + 'date' => 'Le champ :attribute doit être une date valide.', + 'date_equals' => 'Le champ :attribute doit être une date égale à :date.', + 'date_format' => 'Le champ :attribute doit respecter le format :format.', + 'decimal' => 'Le champ :attribute doit avoir :decimal décimales.', + 'declined' => 'Le champ :attribute doit être refusé.', + 'declined_if' => 'Le champ :attribute doit être refusé lorsque :other vaut :value.', + 'different' => 'Le champ :attribute et :other doivent être différents.', + 'digits' => 'Le champ :attribute doit contenir :digits chiffres.', + 'digits_between' => 'Le champ :attribute doit contenir entre :min et :max chiffres.', + 'dimensions' => "Les dimensions de l'image :attribute sont invalides.", + 'distinct' => 'Le champ :attribute contient une valeur en double.', + 'doesnt_contain' => 'Le champ :attribute ne doit pas contenir les valeurs suivantes : :values.', + 'doesnt_end_with' => 'Le champ :attribute ne doit pas se terminer par une des valeurs suivantes : :values.', + 'doesnt_start_with' => 'Le champ :attribute ne doit pas commencer par une des valeurs suivantes : :values.', + 'email' => 'Le champ :attribute doit être une adresse email valide.', + 'encoding' => 'Le champ :attribute doit être encodé en :encoding.', + 'ends_with' => 'Le champ :attribute doit se terminer par une des valeurs suivantes : :values.', + 'enum' => 'Le champ :attribute sélectionné est invalide.', + 'exists' => 'Le champ :attribute sélectionné est invalide.', + 'extensions' => 'Le champ :attribute doit avoir une des extensions suivantes : :values.', + 'file' => 'Le champ :attribute doit être un fichier.', + 'filled' => 'Le champ :attribute doit avoir une valeur.', + 'gt' => [ + 'array' => 'Le champ :attribute doit contenir plus de :value éléments.', + 'file' => 'Le fichier :attribute doit peser plus de :value kilo-octets.', + 'numeric' => 'Le champ :attribute doit être supérieur à :value.', + 'string' => 'Le champ :attribute doit contenir plus de :value caractères.', + ], + 'gte' => [ + 'array' => 'Le champ :attribute doit contenir au moins :value éléments.', + 'file' => 'Le fichier :attribute doit peser au moins :value kilo-octets.', + 'numeric' => 'Le champ :attribute doit être supérieur ou égal à :value.', + 'string' => 'Le champ :attribute doit contenir au moins :value caractères.', + ], + 'hex_color' => 'Le champ :attribute doit être une couleur hexadécimale valide.', + 'image' => 'Le champ :attribute doit être une image.', + 'in' => 'Le champ :attribute sélectionné est invalide.', + 'in_array' => 'Le champ :attribute doit exister dans :other.', + 'in_array_keys' => 'Le champ :attribute doit contenir au moins une des clés suivantes : :values.', + 'integer' => 'Le champ :attribute doit être un entier.', + 'ip' => 'Le champ :attribute doit être une adresse IP valide.', + 'ipv4' => 'Le champ :attribute doit être une adresse IPv4 valide.', + 'ipv6' => 'Le champ :attribute doit être une adresse IPv6 valide.', + 'json' => 'Le champ :attribute doit être une chaîne JSON valide.', + 'list' => 'Le champ :attribute doit être une liste.', + 'lowercase' => 'Le champ :attribute doit être en minuscules.', + 'lt' => [ + 'array' => 'Le champ :attribute doit contenir moins de :value éléments.', + 'file' => 'Le fichier :attribute doit peser moins de :value kilo-octets.', + 'numeric' => 'Le champ :attribute doit être inférieur à :value.', + 'string' => 'Le champ :attribute doit contenir moins de :value caractères.', + ], + 'lte' => [ + 'array' => 'Le champ :attribute ne doit pas contenir plus de :value éléments.', + 'file' => 'Le fichier :attribute doit peser au maximum :value kilo-octets.', + 'numeric' => 'Le champ :attribute doit être inférieur ou égal à :value.', + 'string' => 'Le champ :attribute doit contenir au maximum :value caractères.', + ], + 'mac_address' => 'Le champ :attribute doit être une adresse MAC valide.', + 'max' => [ + 'array' => 'Le champ :attribute ne doit pas contenir plus de :max éléments.', + 'file' => 'Le fichier :attribute ne doit pas dépasser :max kilo-octets.', + 'numeric' => 'Le champ :attribute ne doit pas être supérieur à :max.', + 'string' => 'Le champ :attribute ne doit pas contenir plus de :max caractères.', + ], + 'max_digits' => 'Le champ :attribute ne doit pas contenir plus de :max chiffres.', + 'mimes' => 'Le champ :attribute doit être un fichier de type : :values.', + 'mimetypes' => 'Le champ :attribute doit être un fichier de type : :values.', + 'min' => [ + 'array' => 'Le champ :attribute doit contenir au moins :min éléments.', + 'file' => 'Le fichier :attribute doit peser au moins :min kilo-octets.', + 'numeric' => 'Le champ :attribute doit être au moins :min.', + 'string' => 'Le champ :attribute doit contenir au moins :min caractères.', + ], + 'min_digits' => 'Le champ :attribute doit contenir au moins :min chiffres.', + 'missing' => 'Le champ :attribute doit être absent.', + 'missing_if' => 'Le champ :attribute doit être absent lorsque :other vaut :value.', + 'missing_unless' => 'Le champ :attribute doit être absent sauf si :other vaut :value.', + 'missing_with' => 'Le champ :attribute doit être absent lorsque :values est présent.', + 'missing_with_all' => 'Le champ :attribute doit être absent lorsque :values sont présents.', + 'multiple_of' => 'Le champ :attribute doit être un multiple de :value.', + 'not_in' => 'Le champ :attribute sélectionné est invalide.', + 'not_regex' => 'Le format du champ :attribute est invalide.', + 'numeric' => 'Le champ :attribute doit être un nombre.', + 'password' => [ + 'letters' => 'Le champ :attribute doit contenir au moins une lettre.', + 'mixed' => 'Le champ :attribute doit contenir au moins une majuscule et une minuscule.', + 'numbers' => 'Le champ :attribute doit contenir au moins un chiffre.', + 'symbols' => 'Le champ :attribute doit contenir au moins un symbole.', + 'uncompromised' => 'Le champ :attribute fourni est apparu dans une fuite de données. Veuillez en choisir un autre.', + ], + 'present' => 'Le champ :attribute doit être présent.', + 'present_if' => 'Le champ :attribute doit être présent lorsque :other vaut :value.', + 'present_unless' => 'Le champ :attribute doit être présent sauf si :other vaut :value.', + 'present_with' => 'Le champ :attribute doit être présent lorsque :values est présent.', + 'present_with_all' => 'Le champ :attribute doit être présent lorsque :values sont présents.', + 'prohibited' => 'Le champ :attribute est interdit.', + 'prohibited_if' => 'Le champ :attribute est interdit lorsque :other vaut :value.', + 'prohibited_if_accepted' => 'Le champ :attribute est interdit lorsque :other est accepté.', + 'prohibited_if_declined' => 'Le champ :attribute est interdit lorsque :other est refusé.', + 'prohibited_unless' => 'Le champ :attribute est interdit sauf si :other est dans :values.', + 'prohibits' => 'Le champ :attribute interdit la présence de :other.', + 'regex' => 'Le format du champ :attribute est invalide.', + 'required' => 'Le champ :attribute est obligatoire.', + 'required_array_keys' => 'Le champ :attribute doit contenir des entrées pour : :values.', + 'required_if' => 'Le champ :attribute est obligatoire lorsque :other vaut :value.', + 'required_if_accepted' => 'Le champ :attribute est obligatoire lorsque :other est accepté.', + 'required_if_declined' => 'Le champ :attribute est obligatoire lorsque :other est refusé.', + 'required_unless' => 'Le champ :attribute est obligatoire sauf si :other est dans :values.', + 'required_with' => 'Le champ :attribute est obligatoire lorsque :values est présent.', + 'required_with_all' => 'Le champ :attribute est obligatoire lorsque :values sont présents.', + 'required_without' => "Le champ :attribute est obligatoire lorsque :values n'est pas présent.", + 'required_without_all' => "Le champ :attribute est obligatoire lorsqu'aucun de :values n'est présent.", + 'same' => 'Le champ :attribute doit correspondre à :other.', + 'size' => [ + 'array' => 'Le champ :attribute doit contenir :size éléments.', + 'file' => 'Le fichier :attribute doit peser :size kilo-octets.', + 'numeric' => 'Le champ :attribute doit être égal à :size.', + 'string' => 'Le champ :attribute doit contenir :size caractères.', + ], + 'starts_with' => 'Le champ :attribute doit commencer par une des valeurs suivantes : :values.', + 'string' => 'Le champ :attribute doit être une chaîne de caractères.', + 'timezone' => 'Le champ :attribute doit être un fuseau horaire valide.', + 'unique' => 'Le champ :attribute est déjà utilisé.', + 'uploaded' => 'Le téléversement du champ :attribute a échoué.', + 'uppercase' => 'Le champ :attribute doit être en majuscules.', + 'url' => 'Le champ :attribute doit être une URL valide.', + 'ulid' => 'Le champ :attribute doit être un ULID valide.', + 'uuid' => 'Le champ :attribute doit être un UUID valide.', + + 'custom' => [], + + 'attributes' => [ + 'avatar' => 'avatar', + 'bio' => 'bio', + 'calories' => 'calories', + 'calories_burned' => 'calories brûlées', + 'caption' => 'description', + 'carbs' => 'glucides', + 'code' => 'code', + 'comment' => 'commentaire', + 'date' => 'date', + 'diet_type' => 'type de régime', + 'distance_meters' => 'distance', + 'duration_seconds' => 'durée', + 'eaten_at' => 'date du repas', + 'email' => 'adresse email', + 'error' => 'erreur', + 'expo_push_token' => 'token push Expo', + 'external_id' => 'identifiant externe', + 'fats' => 'lipides', + 'height' => 'taille', + 'image' => 'image', + 'image_url' => 'image', + 'ingredients' => 'ingrédients', + 'ingredients.*.ingredient' => 'ingrédient', + 'ingredients.*.position' => 'position', + 'ingredients.*.quantity' => 'quantité', + 'ingredients.*.unit' => 'unité', + 'meal_posts_id' => 'repas', + 'month' => 'mois', + 'name' => 'nom', + 'nutritionGoals' => 'objectifs nutritionnels', + 'nutritionGoals.calories' => 'objectif de calories', + 'nutritionGoals.carbs' => 'objectif de glucides', + 'nutritionGoals.fats' => 'objectif de lipides', + 'nutritionGoals.proteins' => 'objectif de protéines', + 'page' => 'page', + 'password' => 'mot de passe', + 'per_page' => 'éléments par page', + 'period' => 'période', + 'platform' => 'plateforme', + 'position' => 'position', + 'proteins' => 'protéines', + 'quantity' => 'quantité', + 'rating' => 'note', + 'scope' => 'scope', + 'source' => 'source', + 'started_at' => 'date de début', + 'state' => 'state', + 'title' => 'titre', + 'type' => 'type', + 'unit' => 'unité', + 'visibility' => 'visibilité', + ], +]; diff --git a/tests/Feature/AccountDeletionTest.php b/tests/Feature/AccountDeletionTest.php index 9a9dd51..055078b 100644 --- a/tests/Feature/AccountDeletionTest.php +++ b/tests/Feature/AccountDeletionTest.php @@ -60,7 +60,7 @@ it('deletes the authenticated account and related data', function () { $this->deleteJson('/api/auth/me') ->assertOk() - ->assertJsonPath('message', 'Compte supprimé avec succès'); + ->assertJsonPath('message', __('api.auth.deleted')); $this->assertDatabaseMissing('users', ['id' => $user->getKey()]); $this->assertDatabaseMissing('meal_posts', ['id' => $localMealPost->getKey()]); diff --git a/tests/Feature/EmailVerificationTest.php b/tests/Feature/EmailVerificationTest.php index 9cdabc4..ae0d699 100644 --- a/tests/Feature/EmailVerificationTest.php +++ b/tests/Feature/EmailVerificationTest.php @@ -50,7 +50,7 @@ it('verifies a user from a signed email link', function () { $this->getJson($url) ->assertOk() - ->assertJsonPath('message', 'Compte vérifié avec succès.') + ->assertJsonPath('message', __('api.auth.verified')) ->assertJsonPath('user.emailVerified', true); expect($user->fresh()->hasVerifiedEmail())->toBeTrue(); @@ -78,7 +78,7 @@ it('blocks login for unverified users', function () { 'password' => 'password', ]) ->assertForbidden() - ->assertJsonPath('message', 'Vérifie ton adresse email avant de te connecter.') + ->assertJsonPath('message', __('api.auth.email_not_verified')) ->assertCookieMissing('token'); $this->assertDatabaseMissing('personal_access_tokens', [ @@ -109,7 +109,7 @@ it('resends a verification email for an authenticated unverified user', function $this->postJson('/api/auth/email/verification-notification') ->assertOk() - ->assertJsonPath('message', 'Email de vérification envoyé.'); + ->assertJsonPath('message', __('api.auth.verification_sent')); Notification::assertSentTo($user, VerifyEmail::class); }); diff --git a/tests/Feature/PostReviewsControllerTest.php b/tests/Feature/PostReviewsControllerTest.php index f4d887b..7168f7d 100644 --- a/tests/Feature/PostReviewsControllerTest.php +++ b/tests/Feature/PostReviewsControllerTest.php @@ -35,7 +35,7 @@ it('creates one review per user for a meal post', function () { 'rating' => 4, ]) ->assertConflict() - ->assertJsonPath('message', 'Vous avez déjà donné un avis pour ce repas.'); + ->assertJsonPath('message', __('api.post_reviews.already_exists')); expect(PostReviews::query()->count())->toBe(1); }); diff --git a/tests/Feature/StravaConnectionTest.php b/tests/Feature/StravaConnectionTest.php index 63b7945..026beaa 100644 --- a/tests/Feature/StravaConnectionTest.php +++ b/tests/Feature/StravaConnectionTest.php @@ -212,5 +212,5 @@ it('requires an activity read scope before syncing strava activities', function $this ->postJson('/api/strava/sync') ->assertUnprocessable() - ->assertJsonPath('message', 'La connexion Strava doit autoriser le scope activity:read ou activity:read_all.'); + ->assertJsonPath('message', __('api.strava.missing_activity_scope')); });