]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
- added version check for ruby/gettext, too low or high versions will not be loaded
authorYaohan Chen <yaohan.chen@gmail.com>
Wed, 18 Jul 2007 17:18:13 +0000 (17:18 +0000)
committerYaohan Chen <yaohan.chen@gmail.com>
Wed, 18 Jul 2007 17:18:13 +0000 (17:18 +0000)
  and fallback is done
- updated comments in load_gettext.rb
- moved requires in relevant code sections

lib/rbot/load-gettext.rb

index c7c45cf53236ca3eb1daf64e74de24b6fb081a90..8a74a1d1d31af52db4560503e772f4b4ab69593e 100644 (file)
@@ -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)