Module: BabelFish
- Defined in:
- lib/babelfish.rb
Overview
Ruby interface to Yahoo! BabelFish translation service.
Constant Summary collapse
- PROJECT =
project information
'babelfish'
- VERSION =
'0.0.1'
- RELEASE =
'2008-12-30'
- WEBSITE =
"http://snk.tuxfamily.org/lib/#{PROJECT}"
- SUMMARY =
'Ruby interface to Yahoo! BabelFish translation service.'
- DISPLAY =
PROJECT + ' ' + VERSION
- INSTALL =
File.(File.join(File.dirname(__FILE__), '..'))
- SERVICE_URI =
the URI through which the translation service is accessed
URI.parse('http://babelfish.yahoo.com/translate_txt')
- LANGUAGE_NAMES =
Provides access to a languageās name when given a language code.
{}
- LANGUAGE_PAIRS =
Provides access to a list of destination language codes when given a source language code. In other words, this hash tells you the possible translations that are supported by the service.
Hash.new {|h,k| h[k] = Set.new }
- LANGUAGE_CODES =
A list of possible language codes supported by the service.
LANGUAGE_PAIRS.keys
Class Method Summary collapse
-
.translate(input_text, input_lang_code, output_lang_code, output_encoding = 'utf-8') ⇒ Object
Translates the given input from the given source language into the given destination language.
Class Method Details
.translate(input_text, input_lang_code, output_lang_code, output_encoding = 'utf-8') ⇒ Object
Translates the given input from the given source language into the given destination language.
- input_text
-
the text you want to translate
- input_lang_code
-
the code of the language in which the input text is written
- output_lang_code
-
language code of the result of translation
- output_encoding
-
desired encoding of the result of translation
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/babelfish.rb', line 64 def BabelFish.translate input_text, input_lang_code, output_lang_code, output_encoding = 'utf-8' output_page = Net::HTTP.post_form( SERVICE_URI, :eo => output_encoding, :lp => "#{input_lang_code}_#{output_lang_code}", :trtext => input_text.to_s ) doc = Hpricot(output_page.body) (doc / '#result' / 'div').inner_html end |