From: Yaohan Chen Date: Wed, 18 Jul 2007 17:18:13 +0000 (+0000) Subject: - added version check for ruby/gettext, too low or high versions will not be loaded X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=dda088467e4cfdd776d291396f596395e641bbc2;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git - added version check for ruby/gettext, too low or high versions will not be loaded and fallback is done - updated comments in load_gettext.rb - moved requires in relevant code sections --- diff --git a/lib/rbot/load-gettext.rb b/lib/rbot/load-gettext.rb index c7c45cf5..8a74a1d1 100644 --- a/lib/rbot/load-gettext.rb +++ b/lib/rbot/load-gettext.rb @@ -1,17 +1,26 @@ # load gettext module and provide fallback in case of failure -require 'stringio' +class GetTextVersionError < Exception +end # try to load gettext, or provide fake getttext functions begin + require 'gettext/version' + + gettext_version = GetText::VERSION.split('.').map {|n| n.to_i} + include Comparable # required for Array#between? + raise GetTextVersionError unless gettext_version.between? [1, 8, 0], [1, 10, 0] + require 'gettext' + include GetText + bindtextdomain 'rbot' module GetText - # patch for ruby-gettext 1.9.0 to cope with anonymous modules used by rbot + # patch for ruby-gettext 1.8.0 up to 1.10.0 (and more?) to cope with anonymous + # modules used by rbot # FIXME remove the patch when ruby-gettext is fixed, or rbot switches to named modules - # fix for module names that are not constant names if !instance_methods.include?('orig_bound_targets') alias :orig_bound_targets :bound_targets end @@ -21,6 +30,7 @@ begin end begin + require 'stringio' gettext_info = StringIO.new current_textdomain_info(:out=>gettext_info) # fails sometimes debug 'using ruby-gettext' @@ -29,8 +39,8 @@ begin warn "ruby-gettext was loaded but appears to be non-functional. maybe an mo file doesn't exist for your locale." end -rescue LoadError - warn 'ruby-gettext package not available; translations are disabled' +rescue LoadError, GetTextVersionError + warn 'ruby-gettext package not available, or its version is unsupported; translations are disabled' # dummy functions that return msg_id without translation def _(s)