Skip to content

@dmitry /ya-slovari.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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 = "http://m.slovari.yandex.ru/search.xml?text=#{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
end
end
p translate('машина', 'es-ru-es')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.