summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-07-05 15:36:21 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-07-05 15:37:06 +0200
commitb3aa806886587e5736f9cc338cc1c464e8d113ed (patch)
tree57340103258a2e621319b62aeb0fc3cf7e206101 /lib
parent8ff8b7068c315d10f5a77fc7952e0ccadf7805bc (diff)
load-gettext: cope with ruby gettext 2.1.0
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/load-gettext.rb38
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/rbot/load-gettext.rb b/lib/rbot/load-gettext.rb
index b896557b..5e2ec186 100644
--- a/lib/rbot/load-gettext.rb
+++ b/lib/rbot/load-gettext.rb
@@ -58,6 +58,41 @@ end
require 'stringio'
+ # GetText 2.1.0 does not provide current_textdomain_info,
+ # so we adapt the one from 1.9.10
+ # TODO we would _really_ like to have a future-proof version of this,
+ # but judging by the ruby gettext source code, this isn't going to
+ # happen anytime soon.
+ if not respond_to? :current_textdomain_info
+ # Show the current textdomain information. This function is for debugging.
+ # * options: options as a Hash.
+ # * :with_messages - show informations with messages of the current mo file. Default is false.
+ # * :out - An output target. Default is STDOUT.
+ # * :with_paths - show the load paths for mo-files.
+ def current_textdomain_info(options = {})
+ opts = {:with_messages => false, :with_paths => false, :out => STDOUT}.merge(options)
+ ret = nil
+ # this is for 2.1.0
+ TextDomainManager.each_textdomains(self) {|textdomain, lang|
+ opts[:out].puts "TextDomain name: #{textdomain.name.inspect}"
+ opts[:out].puts "TextDomain current locale: #{lang.to_s.inspect}"
+ opts[:out].puts "TextDomain current mo path: #{textdomain.instance_variable_get(:@locale_path).current_path(lang).inspect}"
+ if opts[:with_paths]
+ opts[:out].puts "TextDomain locale file paths:"
+ textdomain.locale_paths.each do |v|
+ opts[:out].puts " #{v}"
+ end
+ end
+ if opts[:with_messages]
+ opts[:out].puts "The messages in the mo file:"
+ textdomain.current_mo.each{|k, v|
+ opts[:out].puts " \"#{k}\": \"#{v}\""
+ }
+ end
+ }
+ end
+ end
+
# This method is used to output debug information on the GetText
# textdomain, and it's called by the language setting routines
# in rbot
@@ -66,7 +101,8 @@ end
gettext_info = StringIO.new
current_textdomain_info(:out => gettext_info) # fails sometimes
rescue Exception
- warning "gettext failed to set call textdomain info. maybe an mo file doesn't exist for your locale."
+ warning "failed to retrieve textdomain info. maybe an mo file doesn't exist for your locale."
+ debug $!
ensure
gettext_info.string.each_line { |l| debug l}
end