Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if package.config:sub(1, 1) == '\\' then
- os.execute('chcp 65001')
- end
- local api_key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
- local https = require'ssl.https'
- local url = require'urlencode'
- local json = require'cjson.safe'
- print('#Введи текст для перевода#')
- while true do
- local text = io.read()
- text = url.encode(text)
- local response, err = https.request(
- 'https://translation.googleapis.com/language/translate/v2',
- 'q='..text..'&source=en&target=ru&key=' .. api_key
- )
- if not response then
- print(err)
- goto continue
- end
- response, err = json.decode(response)
- if not response then
- print(err)
- goto continue
- end
- local translations = response.data.translations
- for k, v in pairs(translations) do
- print('> ' .. v.translatedText)
- end
- ::continue::
- end
Add Comment
Please, Sign In to add comment