diff options
author | Yaohan Chen <yaohan.chen@gmail.com> | 2010-05-21 17:11:59 -0400 |
---|---|---|
committer | Yaohan Chen <yaohan.chen@gmail.com> | 2010-05-21 17:11:59 -0400 |
commit | 1d5f42447b9dafef851eee4a72430e512604278f (patch) | |
tree | e3d6c771852fc947a1edd93a56103c045a7dafb8 /data | |
parent | 027b6965f5abf5d05a95d4dc627f19a71b7a7076 (diff) |
translator: fix undefined variable
Fix an error in commit 027b6965f5abf5d05a95 which causes @lang_list to
be undefined but used in BabelFish.
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/translator.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/data/rbot/plugins/translator.rb b/data/rbot/plugins/translator.rb index 9fb74e8a..2e7be919 100644 --- a/data/rbot/plugins/translator.rb +++ b/data/rbot/plugins/translator.rb @@ -215,18 +215,24 @@ class BabelfishTranslator < Translator def initialize(cache) require 'mechanize' - form = WWW::Mechanize.new.get('http://babelfish.altavista.com/babelfish/'). - forms_with(:name => 'frmTrText').first - lang_list = form.fields_with(:name => 'lp').first + (_, lang_list) = parse_page language_pairs = lang_list.options.map {|o| o.value.split('_')}. reject {|p| p.empty?} super(Translator::Direction.pairs(language_pairs), cache) end - def do_translate(text, from, to) - @form ||= WWW::Mechanize.new.get('http://babelfish.altavista.com/babelfish/'). - forms_with(:name => 'frmTrText').first + def parse_page + form = WWW::Mechanize.new.get('http://babelfish.altavista.com/babelfish/'). + forms_with(:name => 'frmTrText').first + lang_list = form.fields_with(:name => 'lp').first + [form, lang_list] + end + def do_translate(text, from, to) + unless @form && @lang_list + @form, @lang_list = parse_page + end + if @form.fields_with(:name => 'trtext').empty? @form.add_field!('trtext', text) else |