Skip to content

Commit e7ebf31

Browse files
author
Hendrik Jäger
committed
minor fixes: rubocop and roddi warnings
1 parent 9479d93 commit e7ebf31

1 file changed

Lines changed: 30 additions & 33 deletions

File tree

lib/rbot/load-gettext.rb

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class GetTextVersionError < Exception
1010

1111
# try to load gettext, or provide fake gettext functions
1212
begin
13-
# workaround for gettext not checking empty LANGUAGE
14-
if ENV["LANGUAGE"] and ENV["LANGUAGE"].empty?
15-
ENV.delete "LANGUAGE"
16-
end
13+
# workaround for gettext not checking empty LANGUAGE
14+
if ENV['LANGUAGE'] and ENV['LANGUAGE'].empty?
15+
ENV.delete 'LANGUAGE'
16+
end
1717

1818
require 'gettext/version'
1919

20-
gettext_version = GetText::VERSION.split('.').map {|n| n.to_i}
20+
gettext_version = GetText::VERSION.split('.').map { |n| n.to_i }
2121
class ::Array
2222
include Comparable # for Array#>=
2323
end
@@ -29,10 +29,12 @@ class ::Array
2929

3030
include GetText
3131

32-
rbot_locale_path = File.join(Irc::Bot::Config.datadir,
32+
rbot_locale_path = File.join(
33+
Irc::Bot::Config.datadir,
3334
gettext_version < [2, 2, 0] ?
3435
"../locale/%{locale}/LC_MESSAGES/%{name}.mo" :
35-
"../locale/%{lang}/LC_MESSAGES/%{name}.mo")
36+
"../locale/%{lang}/LC_MESSAGES/%{name}.mo"
37+
)
3638

3739
if gettext_version < [2, 0, 0]
3840
add_default_locale_path(rbot_locale_path)
@@ -69,8 +71,6 @@ def self.all_load_paths
6971
retry
7072
end
7173

72-
73-
7474
module GetText
7575
# patch for ruby-gettext 1.x to cope with anonymous modules used by rbot.
7676
# bound_targets and related methods are not used nor present in 2.x, and
@@ -88,7 +88,7 @@ def bound_targets(*a) # :nodoc:
8888

8989
# GetText 2.1.0 does not provide current_textdomain_info,
9090
# so we adapt the one from 1.9.10
91-
# TODO we would _really_ like to have a future-proof version of this,
91+
# TODO: we would _really_ like to have a future-proof version of this,
9292
# but judging by the ruby gettext source code, this isn't going to
9393
# happen anytime soon.
9494
if not respond_to? :current_textdomain_info
@@ -101,51 +101,48 @@ def current_textdomain_info(options = {})
101101
opts = {:with_messages => false, :with_paths => false, :out => STDOUT}.merge(options)
102102
ret = nil
103103
# this is for 2.1.0
104-
TextDomainManager.each_text_domains(self) {|textdomain, lang|
104+
TextDomainManager.each_text_domains(self) do |textdomain, lang|
105105
opts[:out].puts "TextDomain name: #{textdomain.name.inspect}"
106106
opts[:out].puts "TextDomain current locale: #{lang.to_s.inspect}"
107107
opts[:out].puts "TextDomain current mo path: #{textdomain.instance_variable_get(:@locale_path).current_path(lang).inspect}"
108108
if opts[:with_paths]
109-
opts[:out].puts "TextDomain locale file paths:"
109+
opts[:out].puts 'TextDomain locale file paths:'
110110
textdomain.locale_paths.each do |v|
111111
opts[:out].puts " #{v}"
112112
end
113113
end
114114
if opts[:with_messages]
115-
opts[:out].puts "The messages in the mo file:"
116-
textdomain.current_mo.each{|k, v|
115+
opts[:out].puts 'The messages in the mo file:'
116+
textdomain.current_mo.each do |k, v|
117117
opts[:out].puts " \"#{k}\": \"#{v}\""
118-
}
118+
end
119119
end
120-
}
120+
end
121121
end
122122
end
123123

124124
# This method is used to output debug information on the GetText
125125
# textdomain, and it's called by the language setting routines
126126
# in rbot
127127
def rbot_gettext_debug
128-
begin
129-
gettext_info = StringIO.new
130-
current_textdomain_info(:out => gettext_info) # fails sometimes
131-
rescue Exception
132-
warning "failed to retrieve textdomain info. maybe an mo file doesn't exist for your locale."
133-
debug $!
134-
ensure
135-
gettext_info.string.each_line { |l| debug l}
136-
end
128+
gettext_info = StringIO.new
129+
current_textdomain_info(:out => gettext_info) # fails sometimes
130+
rescue Exception
131+
warning "failed to retrieve textdomain info. maybe an mo file doesn't exist for your locale."
132+
debug $!
133+
ensure
134+
gettext_info.string.each_line { |l| debug l }
137135
end
138136
end
139137

140138
log "gettext loaded"
141-
142139
rescue LoadError, GetTextVersionError
143140
warning "failed to load ruby-gettext package: #{$!}; translations are disabled"
144141

145142
# undefine GetText, in case it got defined because the error was caused by a
146143
# wrong version
147144
if defined?(GetText)
148-
Object.module_eval { remove_const("GetText") }
145+
Object.module_eval { remove_const('GetText') }
149146
end
150147

151148
# dummy functions that return msg_id without translation
@@ -211,19 +208,19 @@ class String
211208
#
212209
# (e.g.) "%{firstname}, %{familyname}" % {:firstname => "Masao", :familyname => "Mutoh"}
213210
def %(args)
214-
if args.kind_of?(Hash)
211+
if args.is_a?(Hash)
215212
ret = dup
216-
args.each {|key, value|
213+
args.each do |key, value|
217214
ret.gsub!(/\%\{#{key}\}/, value.to_s)
218-
}
215+
end
219216
ret
220217
else
221218
ret = gsub(/%\{/, '%%{')
222219
begin
223-
ret._old_format_m(args)
220+
ret._old_format_m(args)
224221
rescue ArgumentError
225-
$stderr.puts " The string:#{ret}"
226-
$stderr.puts " args:#{args.inspect}"
222+
$stderr.puts " The string:#{ret}"
223+
$stderr.puts " args:#{args.inspect}"
227224
end
228225
end
229226
end

0 commit comments

Comments
 (0)