Translate text in Chrome Extension using undocumented API

The Google Dictionary Chrome extension makes requests like this to do translations:

https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=en&tl=ru&q=text

We can do the same (for the moment at least):

fetch(
  "https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=en&tl=ru&q=text"
).then(function(res) {
  res.text().then(function(r) {
    let code = ''+r;
    log(code)
  })
})

Result:

{
    "sentences": [{
        "trans": "текст",
        "orig": "text",
        "backend": 2
    }, {
        "translit": "tekst",
        "src_translit": "tekst"
    }],
    "dict": [{
        "pos": "noun",
        "terms": ["текст", "тема", "оригинал", "руководство", "подлинный текст", "цитата из библии"],
        "entry": [{
            "word": "текст",
            "reverse_translation": ["text", "word", "version", "document", "book"],
            "score": 0.51075
        }, {
            "word": "тема",
            "reverse_translation": ["topic", "theme", "subject", "text", "chapter", "burden"],
            "score": 5.3077896e-05
        }, {
            "word": "оригинал",
            "reverse_translation": ["original", "master", "eccentric", "text", "character", "oddball"],
            "score": 1.5936874e-05
        }, {
            "word": "руководство",
            "reverse_translation": ["manual", "guide", "leadership", "guidance", "direction", "text"],
            "score": 4.9370133e-06
        }, {
            "word": "подлинный текст",
            "reverse_translation": ["text"],
            "score": 3.9670017e-06
        }, {
            "word": "цитата из библии",
            "reverse_translation": ["scripture", "text"],
            "score": 1.9638082e-06
        }],
        "base_form": "text",
        "pos_enum": 1
    }, {
        "pos": "verb",
        "terms": ["писать крупным почерком"],
        "entry": [{
            "word": "писать крупным почерком",
            "reverse_translation": ["text"]
        }],
        "base_form": "text",
        "pos_enum": 2
    }],
    "src": "en",
    "alternative_translations": [{
        "src_phrase": "text",
        "alternative": [{
            "word_postproc": "текст",
            "score": 1000,
            "has_preceeding_space": true,
            "attach_to_next_token": false
        }],
        "srcunicodeoffsets": [{
            "begin": 0,
            "end": 4
        }],
        "raw_src_segment": "text",
        "start_pos": 0,
        "end_pos": 0
    }],
    "confidence": 0.88932037,
    "ld_result": {
        "srclangs": ["en"],
        "srclangs_confidences": [0.88932037],
        "extended_srclangs": ["en"]
    }
}

To convert it to a js object just call JSON.parse on it! ]

 

shitpoet@gmail.com

 

free hit counters