“google translate” vs “translate api”

后端 未结 3 703
清歌不尽
清歌不尽 2020-12-17 02:40

I hear that the Translate API will be charged for, but what exactly prevents us form using the free Google Translate service here for free ? Otherwise put, what are the limi

3条回答
  •  星月不相逢
    2020-12-17 03:13

    $translatedText = "प्रशांत कुमार सिंह";
    $detectedSourceLanguage = "en";
    
    $url ='https://www.google.com/inputtools/request?text='.urlencode($translatedText).'&ime=transliteration_hi_'.urlencode($detectedSourceLanguage);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_PROXYPORT,3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    $response = curl_exec($ch);
    $output = json_decode($response);
    $resultText = '';
    
    if($output[0] == 'SUCCESS'){
     if(isset($output[1])){
      if(isset($output[1][0])){
       if(isset($output[1][0][1])){
        $resultText = $output[1][0][1][0];
       }
      }
     }
    }
    echo  $resultText;
    

提交回复
热议问题