PATH:
home
/
rwabteecom
/
project_11
/
app
/
Console
/
Commands
/
Editing: TranslateCommand.php
<?php namespace App\Console\Commands; use App\Helpers\Translate; use Artisan; use File; use Illuminate\Console\Command; use Stichoza\GoogleTranslate\GoogleTranslate; class TranslateCommand extends Command { protected $signature = 'trans-files'; protected $description = 'Translate files existing in lang folder into [ar] lang'; public function handle(): void { Artisan::call("translation:sync-missing-translation-keys"); $enWords = json_decode(file_get_contents(base_path("lang/ar.json")), true); $arWords = []; foreach ($enWords as $key => $value) { if ($value == "") { $arWords[$key] = Translate::translate("ar", $key); } else { $arWords[$key] = $value; } } File::put(base_path("lang/ar.json"), json_encode($arWords, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } public static function translate($to, $word, $from = null): ?string { if (!is_null($word)) { $googleTranslate = new GoogleTranslate(); if ($from == null) { $googleTranslate->setSource(); } else { $googleTranslate->setSource($from); } $googleTranslate->setTarget($to); return $googleTranslate->translate($word); } return $word ?? ""; } }
SAVE
CANCEL