Skip to content

Commit

Permalink
implement and consider lang files
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Sep 20, 2023
1 parent c5c4d77 commit 874aefc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions resources/lang/en/otp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'throttle' => 'Too many OTP attempts. Please try again in :seconds seconds.',
];
5 changes: 5 additions & 0 deletions resources/lang/fa/otp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'throttle' => 'درخواست بیش از حد مجاز! لطفا بعد از :seconds ثانیه دوباره امتحان کنید',
];
4 changes: 3 additions & 1 deletion src/OtpManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public function sendAndRetryCheck(string $mobile, string $type): SentOtpDto
return $this->send($mobile, $type);
}

$remainingTime = $retryAfter->diffInSeconds(Carbon::now());

throw ValidationException::withMessages([
'otp' => [
trans('auth.throttle', ['seconds' => $this->waitingTime]),
trans('OtpManager::otp.throttle', ['seconds' => $remainingTime]),
],
]);
}
Expand Down
25 changes: 11 additions & 14 deletions src/OtpManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ class OtpManagerServiceProvider extends ServiceProvider
*/
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'OtpManager');

// Publishing the lang file.
$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/otp-manager'),
], 'translations');

// Publishing the configuration file.
$this->publishes([
__DIR__.'/../config/otp.php' => config_path('otp.php'),
], 'otp.config');
}

/**
Expand All @@ -23,15 +31,4 @@ public function register(): void
{
$this->mergeConfigFrom(__DIR__.'/../config/otp.php', 'otp');
}

/**
* Console-specific booting.
*/
protected function bootForConsole(): void
{
// Publishing the configuration file.
$this->publishes([
__DIR__.'/../config/otp.php' => config_path('otp.php'),
], 'otp.config');
}
}

0 comments on commit 874aefc

Please sign in to comment.