Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Yandex Slovari (word translation)
%w(rubygems open-uri nokogiri cgi).each {|lib| require lib}
# language directions: en-ru-en de-ru-de fr-ru-fr it-ru-it es-ru-es uk-ru ru-uk kk-ru ru-kk la-ru-la
def translate(text, lang=nil)
url = "{CGI::escape(text)}"
url << "&lang=#{lang}" if lang
data = open(url).read
xml = Nokogiri::HTML(data)
{:translations => []}.tap do |r|
r[:word] = xml.css('.b-title')[0].inner_text
xml.css('.b-translate a').each do |v| r[:translations] << v.inner_text end
p translate('машина', 'es-ru-es')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment