Crystal client for GoogleTranslate
Add this to your application's shard.yml
:
dependencies:
google_translate:
github: greyblake/crystal-google_translate
require "google_translate"
The following code translates german word tanzen
with a typo(double n) and prints the result:
client = GoogleTranslate::Client.new
tr = client.translate("de", "en", "tanzenn")
puts "#{tr.source_lang} -> #{tr.target_lang}"
puts "Query: #{tr.query}"
puts "Corrected query: #{tr.corrected_query}"
puts "Text: #{tr.text}"
tr.variants.each do |word_class, words|
puts word_class
words.each do |word|
puts " #{word}"
end
end
Output:
de -> en
Query: tanzenn
Corrected query: tanzen
Text: dance
verb
dance
hop
spin
bob
foot
To run specs:
crystal spec
- greyblake Sergey Potapov - creator, maintainer