Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iurev/2ffad2b22c78ce77a8cd6bb34e6a3df3 to your computer and use it in GitHub Desktop.
Save iurev/2ffad2b22c78ce77a8cd6bb34e6a3df3 to your computer and use it in GitHub Desktop.
def translate(text)
text = 'Блокнот в клетку'
response = Faraday.post("https://translation.googleapis.com/language/translate/v2?key=#{ENV['GOOGLE_CLOUD_API_KEY']}") do |req|
req.headers['Content-Type'] = 'application/json'
req.body = {
q: text,
target: 'en',
}.to_json
end
begin
JSON.parse(response.body)['data']['translations'][0]['translatedText']
rescue StandardError => _e
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment