%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/app/Console/Commands/ |
Upload File : |
<?php
namespace App\Console\Commands;
use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Stichoza\GoogleTranslate\GoogleTranslate;
class CreateTranslations extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'translations:translate {--translateFrom=} {--translateTo=} {--exclude=}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Auto translate and create files in lang folder';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$from = $this->option('translateFrom');
$to = $this->option('translateTo');
$exclude = $this->option('exclude');
if ($exclude !== null) {
$translations = Translation::where('locale', $from)->whereNotIn('group', explode(',', $exclude))->get();
}
else {
$translations = Translation::where('locale', $from)->get();
}
$tr = new GoogleTranslate();
$tr->setSource($from);
$tr->setTarget($to);
foreach ($translations as $translation) {
$data = [
'locale' => $to,
'group' => $translation->group,
'key' => $translation->key
];
$reqTranslation = Translation::where($data)->first();
if ($reqTranslation === null) {
$data = Arr::add($data, 'value', $tr->translate($translation->value));
Translation::create($data);
}
}
}
}