<commit_before><?php
namespace LangridSettingClient\API\Google;

use LangridSettingClient\API as API;

class GoogleTranslator implements API\Translator {
    var $setting;
    var $response;

    public function __construct($setting) {
        $this->setting = $setting;
    }

    public function translate($from, $to, $text, $dictionary = array()) {

        $res = json_decode($this->sendRequest($from, $to, $text), true);
        if (@$res['error']) {
            throw new API\Exception\ApiException($res['error']['message']);
        }

        return @$res['data']['translations']['translatedText'];
    }

    protected function sendRequest($from, $to, $text) {
        // see https://developers.google.com/translate/v2/using_rest
        $s = curl_init();

        $this->initResponseData();
        curl_setopt_array($s,
            array(
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
                CURLOPT_URL => $this->setting->url,
                CURLOPT_POST => true,
                CURLOPT_WRITEFUNCTION => array($this, 'curlResponseReader'),
                CURLOPT_HTTPHEADER => array('X-HTTP-Method-Override: GET'),
                CURLOPT_POSTFIELDS => $this->buildParameters(
                        array(
                            'key' => $this->setting->apiKey,
                            'source' => $from,
                            'target' => $to,
                            'q' => $text))));

        $res = curl_exec($s);

        if ($res == TRUE) {<commit_msg>JSON問合せ内容の誤りを修正<commit_after><?php
namespace LangridSettingClient\API\Google;

use LangridSettingClient\API as API;

class GoogleTranslator implements API\Translator {
    var $setting;
    var $response;

    public function __construct($setting) {
        $this->setting = $setting;
    }

    public function translate($from, $to, $text, $dictionary = array()) {

        $res = json_decode($this->sendRequest($from, $to, $text), true);
        if (@$res['error']) {
            throw new API\Exception\ApiException($res['error']['message']);
        }

        return @$res['data']['translations'][0]['translatedText'];
    }

    protected function sendRequest($from, $to, $text) {
        // see https://developers.google.com/translate/v2/using_rest
        $s = curl_init();

        $this->initResponseData();
        curl_setopt_array($s,
            array(
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
                CURLOPT_URL => $this->setting->url,
                CURLOPT_POST => true,
                CURLOPT_WRITEFUNCTION => array($this, 'curlResponseReader'),
                CURLOPT_HTTPHEADER => array('X-HTTP-Method-Override: GET'),
                CURLOPT_POSTFIELDS => $this->buildParameters(
                        array(
                            'key' => $this->setting->apiKey,
                            'source' => $from,
                            'target' => $to,
                            'q' => $text))));

        $res = curl_exec($s);

        if ($res == TRUE) {
{'fraction_non_alphanumeric': 0.14130791981597107, 'fraction_numerical': 0.0023003614853762734, 'mean_word_length': 1.9697560975609756, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4308856', 'n_tokens_mistral': 892, 'n_tokens_neox': 846, 'n_words': 158}