Created
October 5, 2021 08:51
-
-
Save iurev/2ffad2b22c78ce77a8cd6bb34e6a3df3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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