Skip to content

Commit

Permalink
fix_API_call_limit_issue (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahkmunna authored and tanmuhittin committed Dec 4, 2019
1 parent 7b4efd1 commit 13eb978
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Commands/TranslateFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class TranslateFilesCommand extends Command
{
public static $request_count = 0;
public static $request_per_sec = 5;
public static $sleep_for_sec = 1;

public $base_locale;
public $locales;
public $excluded_files;
Expand Down Expand Up @@ -131,6 +135,14 @@ public static function translate($base_locale, $locale, $text)
$text = str_replace($match," x".$i,$text);
$i++;
}

// Check if the API request limit reached.
if( self::$request_count >= self::$request_per_sec ){
sleep(self::$sleep_for_sec);
self::$request_count = 0; //Reset the $request_count
}
self::$request_count++; //Increase the request_count by 1

if(config('laravel_google_translate.google_translate_api_key', false)){
$translated = self::translate_via_api_key($base_locale, $locale, $text);
}else{
Expand Down

0 comments on commit 13eb978

Please sign in to comment.