From f90891342f501abce9ecfe8901bf3577b0c98e18 Mon Sep 17 00:00:00 2001 From: saparatayev Date: Mon, 21 Feb 2022 11:11:49 +0500 Subject: [PATCH] fix: translate error and success msgs in email & phone verif --- modules/system/lang/en/validation.php | 10 +++ modules/system/lang/ru/validation.php | 10 +++ modules/system/lang/tm/validation.php | 10 +++ .../api/EmailVerificationController.php | 6 +- .../controllers/api/SmsController.php | 68 ++++++++++++++++--- plugins/rainlab/user/lang/tm/lang.php | 2 +- 6 files changed, 93 insertions(+), 13 deletions(-) diff --git a/modules/system/lang/en/validation.php b/modules/system/lang/en/validation.php index 19721f7d0..93a81b984 100644 --- a/modules/system/lang/en/validation.php +++ b/modules/system/lang/en/validation.php @@ -146,6 +146,16 @@ return [ 'online_payment_failed' => 'Online payment has been failed.', 'bank_payment_saved' => 'The bank transfer payment saved. Admin will consider it and approve later.', 'bank_payment_failed' => 'The bank transfer payment failed.', + // 'contact_message_sent' => 'Contact message has been sent', + 'cannot_verify_invalid_email' => 'Cannot verify. Invalid email address.', + 'verification_link_sent' => 'Verification link has been sent to your email. Log in to tmex.gov.tm before checking your email.', + 'email_already_verified' => 'You have already verified your email address.', + 'sms_sent' => 'SMS has been sent.', + 'sms_not_sent_error' => 'SMS has not been sent. Error.', + 'user_not_tm_resident' => 'This user is not a resident.', + 'phone_already_verified' => 'You have already verified your phone number.', + 'phone_verified_message' => 'Your phone number has been succesfully verified', + 'phone_verification_code_invalid' => 'Invalid sms code', ], /* diff --git a/modules/system/lang/ru/validation.php b/modules/system/lang/ru/validation.php index 3d75072ca..bd4d90341 100644 --- a/modules/system/lang/ru/validation.php +++ b/modules/system/lang/ru/validation.php @@ -146,6 +146,16 @@ return [ 'online_payment_failed' => 'Онлайн оплата не прошла.', 'bank_payment_saved' => 'Оплата банковским переводом сохранена и позже будет проверена администратором.', 'bank_payment_failed' => 'Оплата банковским переводом не прошла.', + // 'contact_message_sent' => 'Письмо отправлено.', + 'cannot_verify_invalid_email' => 'Верификация Email невозможна. Неверный Email', + 'verification_link_sent' => 'Ссылка для подтверждения отправлена на ваш Email. Авторизуйтесь на tmex.gov.tm перед проверкой Email.', + 'email_already_verified' => 'Вы уже подтвердили свой Email.', + 'sms_sent' => 'СМС отправлен.', + 'sms_not_sent_error' => 'СМС не отправлен. Ошибка.', + 'user_not_tm_resident' => 'Пользователь не является резидентом.', + 'phone_already_verified' => 'Номер телефона уже подтвержден.', + 'phone_verified_message' => 'Ваш номер телефона подтвержден', + 'phone_verification_code_invalid' => 'Неверный СМС код', ], /* diff --git a/modules/system/lang/tm/validation.php b/modules/system/lang/tm/validation.php index 8ced5afa9..dede076bd 100644 --- a/modules/system/lang/tm/validation.php +++ b/modules/system/lang/tm/validation.php @@ -148,6 +148,16 @@ return [ 'online_payment_failed' => 'Onlaýn töleg geçmedi.', 'bank_payment_saved' => 'Bank üsti bilen töleg ýazyldy we soňra administrator tarapyndan gözden geçiriler.', 'bank_payment_failed' => 'Bank üsti bilen töleg geçmedi.', + // 'contact_message_sent' => 'Hat ugradyldy.', + 'cannot_verify_invalid_email' => 'Tassyklama grçmedi. El. bukjaňyz nädogry.', + 'verification_link_sent' => 'Tassyklama düwmesi El. bukjaňyza iberildi. El. bukjaňyzy barlamazdan öň tmex.gov.tm-da şahsy hasabyňyza giriň.', + 'email_already_verified' => 'Siziň el. bukjaňyz eýýäm tassyklanan.', + 'sms_sent' => 'SMS iberildi.', + 'sms_not_sent_error' => 'SMS iberilmedi. Ýalňyş.', + 'user_not_tm_resident' => 'Ulanyjy ýerli ýaşaýjy däl.', + 'phone_already_verified' => 'Siziň telefon belgiňiz eýýäm tassyklanan.', + 'phone_verified_message' => 'Siziň telefon belgiňiz tassyklandy', + 'phone_verification_code_invalid' => 'Nädogry SMS kody', ], /* diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/EmailVerificationController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/EmailVerificationController.php index f80f103d3..a15fe171b 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/EmailVerificationController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/EmailVerificationController.php @@ -34,16 +34,16 @@ class EmailVerificationController extends KabinetAPIController } catch(Throwable $th) { \Log::info($th); - return response()->json('Cannot verify. Invalid email address.', 400); + return response()->json(trans('validation.api.cannot_verify_invalid_email', [], $inputData['locale']), 400); } $this->user->email_activation_code = $code; $this->user->save(); - return response()->json('Verification link has been sent. Log in to tmex.gov.tm before checking your email.', 201); + return response()->json(trans('validation.api.verification_link_sent', [], $inputData['locale']), 201); } else { - return response()->json('You have already verified your email address.', 200); + return response()->json(trans('validation.api.email_already_verified', [], $inputData['locale']), 200); } } } diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/SmsController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/SmsController.php index 4ff5ddf54..fd66f1dc5 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/SmsController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/SmsController.php @@ -30,12 +30,24 @@ class SmsController extends KabinetAPIController if($this->user->dial_code != '+993') { return response()->json([ 'dial_code' => $this->user->dial_code, - 'message' => 'This user is not a resident of Turkmenistan.' + 'result' => 1, + 'message' => [ + 'ru' => trans('validation.api.user_not_tm_resident', [], 'ru'), + 'en' => trans('validation.api.user_not_tm_resident', [], 'en'), + 'tm' => trans('validation.api.user_not_tm_resident', [], 'tm'), + ] ], 400); } if($this->user->phone_verified && $this->user->dial_code == '+993') { - return response()->json('User phone already verified', 200); + return response()->json([ + 'result' => 1, + 'message' => [ + 'ru' => trans('validation.api.phone_already_verified', [], 'ru'), + 'en' => trans('validation.api.phone_already_verified', [], 'en'), + 'tm' => trans('validation.api.phone_already_verified', [], 'tm'), + ] + ], 200); } $code = random_int(1000, 9999); @@ -49,21 +61,33 @@ class SmsController extends KabinetAPIController $this->user->save(); return response()->json([ 'result' => $result, - 'message' => 'Message has been succesfully sent' + 'message' => [ + 'ru' => trans('validation.api.sms_sent', [], 'ru'), + 'en' => trans('validation.api.sms_sent', [], 'en'), + 'tm' => trans('validation.api.sms_sent', [], 'tm'), + ] ], 201); break; case 1: return response()->json([ 'result' => $result, - 'message' => 'Error' + 'message' => [ + 'ru' => trans('validation.api.sms_not_sent_error', [], 'ru'), + 'en' => trans('validation.api.sms_not_sent_error', [], 'en'), + 'tm' => trans('validation.api.sms_not_sent_error', [], 'tm'), + ] ], 500); break; default: return response()->json([ 'result' => $result, - 'message' => 'Error' + 'message' => [ + 'ru' => trans('validation.api.sms_not_sent_error', [], 'ru'), + 'en' => trans('validation.api.sms_not_sent_error', [], 'en'), + 'tm' => trans('validation.api.sms_not_sent_error', [], 'tm'), + ] ], 500); break; } @@ -74,12 +98,24 @@ class SmsController extends KabinetAPIController if($this->user->dial_code != '+993') { return response()->json([ 'dial_code' => $this->user->dial_code, - 'message' => 'This user is not a resident of Turkmenistan.' + 'status' => false, + 'message' => [ + 'ru' => trans('validation.api.user_not_tm_resident', [], 'ru'), + 'en' => trans('validation.api.user_not_tm_resident', [], 'en'), + 'tm' => trans('validation.api.user_not_tm_resident', [], 'tm'), + ] ], 400); } if($this->user->phone_verified && $this->user->dial_code == '+993') { - return response()->json('User phone already verified', 200); + return response()->json([ + 'status' => false, + 'message' => [ + 'ru' => trans('validation.api.phone_already_verified', [], 'ru'), + 'en' => trans('validation.api.phone_already_verified', [], 'en'), + 'tm' => trans('validation.api.phone_already_verified', [], 'tm'), + ] + ], 200); } $validator = Validator::make($request->all(), [ @@ -93,9 +129,23 @@ class SmsController extends KabinetAPIController $this->user->phone_verified = true; $this->user->phone_activation_code = null; $this->user->save(); - return response()->json('User phone has been succesfully verified', 201); + return response()->json([ + 'status' => true, + 'message' => [ + 'ru' => trans('validation.api.phone_verified_message', [], 'ru'), + 'en' => trans('validation.api.phone_verified_message', [], 'en'), + 'tm' => trans('validation.api.phone_verified_message', [], 'tm'), + ] + ], 201); } else { - return response()->json('Wrong sms code', 400); + return response()->json([ + 'status' => false, + 'message' => [ + 'ru' => trans('validation.api.phone_verification_code_invalid', [], 'ru'), + 'en' => trans('validation.api.phone_verification_code_invalid', [], 'en'), + 'tm' => trans('validation.api.phone_verification_code_invalid', [], 'tm'), + ] + ], 400); } } } diff --git a/plugins/rainlab/user/lang/tm/lang.php b/plugins/rainlab/user/lang/tm/lang.php index 330c03aae..5e89adfe6 100644 --- a/plugins/rainlab/user/lang/tm/lang.php +++ b/plugins/rainlab/user/lang/tm/lang.php @@ -201,7 +201,7 @@ return [ 'email_verification_check_message' => 'El. bukjaňyzy barlamygyňyzy haýyş edýäris', 'email_verified_message' => 'Siziň el. bukjaňyz tassyklandy', 'email_verification_link_invalid' => 'Tassyklama kody nädogry', - 'email_already_verified' => 'Siz el. bukjaňyz eýýäm tassyklanan', + 'email_already_verified' => 'Siziň el. bukjaňyz eýýäm tassyklanan', 'phone_verified_message' => 'Siziň el telefonyňyz tassyklandy', 'phone_verification_code_invalid' => 'Nädogry SMS kody', ],