<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once '../database.php';
require '../../vendor/autoload.php';

use Google\Cloud\Translate\V2\TranslateClient;

$translate = new TranslateClient([
    'key' => 'AIzaSyC_glMEOPHxXQXSXwETPk0-VLT5Ky7Ixtc'
]);

class Translate extends database
{
    public function getProducts()
    {
        $sql = 'SELECT * FROM tb_product WHERE DATE(cl_created_at)>="2024-02-29" LIMIT 29000,2000 ';
        return $this->callQuery($sql);
    }
    
    public function updateSubCategory($text, $id)
    {
        return $this->update('tb_product', ['cl_name' => $text], ['cl_id' => $id]);
    }
}
     

$obj = new Translate();
$products = $obj->getProducts();

                                                
$count = 0;

foreach($products AS $product)
{
   
   
   
        $result = $translate->translate($product['cl_name'], [
            'source' => 'pl',
            'target' => 'en'
        ]);


        
        $obj->updateSubCategory($result['text'], $product['cl_id']);
    
}
