- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
const translate = require('@google-cloud/translate')();
exports.translate = (req, res) => {
const from = req.query.from
const to = req.query.to
const text = req.query.text
if (!from || !to || !text)
{
return res.status(200).send('')
}
const options = {from: from, to: to }
console.log('sending req back')
translate.translate(text, options, function(e, translation) {
if (!e)
{
res.status(200)
.header('Access-Control-Allow-Origin', '*')
.send(translation);
}
else
{
res.status(200).send('error')
}
})
}