summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorYaohan Chen <yaohan.chen@gmail.com>2007-07-09 08:31:45 +0000
committerYaohan Chen <yaohan.chen@gmail.com>2007-07-09 08:31:45 +0000
commit069d8c8dd5ab841cc5efcfeae1cdc2e7f93c2976 (patch)
tree49df20137605bccaeff99ef4340c0d3551f090f7 /lib/rbot
parent47fd0312cf67aab35ba3cfd3ef898f83b09a7f0f (diff)
integrated ruby-gettext
modified a few files to allow translated messages created gettext template file initialized gettext files for Japanese and Simplified Chinese
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/botuser.rb9
-rw-r--r--lib/rbot/config.rb24
-rw-r--r--lib/rbot/core/auth.rb251
-rw-r--r--lib/rbot/core/basics.rb29
-rw-r--r--lib/rbot/core/config.rb72
-rw-r--r--lib/rbot/ircbot.rb10
-rw-r--r--lib/rbot/load-gettext.rb113
-rw-r--r--lib/rbot/plugins.rb79
-rw-r--r--lib/rbot/registry.rb18
9 files changed, 391 insertions, 214 deletions
diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb
index 9a34b341..8d01632e 100644
--- a/lib/rbot/botuser.rb
+++ b/lib/rbot/botuser.rb
@@ -19,13 +19,13 @@ module Irc
BotConfig.register BotConfigStringValue.new( 'auth.password',
:default => 'rbotauth', :wizard => true,
- :desc => 'Password for the bot owner' )
+ :desc => _('Password for the bot owner'))
BotConfig.register BotConfigBooleanValue.new( 'auth.login_by_mask',
:default => 'true',
- :desc => 'Set false to prevent new botusers from logging in without a password when the user netmask is known')
+ :desc => _('Set false to prevent new botusers from logging in without a password when the user netmask is known'))
BotConfig.register BotConfigBooleanValue.new( 'auth.autologin',
:default => 'true',
- :desc => 'Set false to prevent new botusers from recognizing IRC users without a need to manually login')
+ :desc => _('Set false to prevent new botusers from recognizing IRC users without a need to manually login'))
# BotConfig.register BotConfigIntegerValue.new( 'auth.default_level',
# :default => 10, :wizard => true,
# :desc => 'The default level for new/unknown users' )
@@ -683,7 +683,8 @@ module Irc
else
# cmds = cmdtxt.split('::')
# @bot.say chan, "you don't have #{cmds.last} (#{cmds.first}) permissions here" if chan
- @bot.say chan, "#{user}, you don't have '#{cmdtxt}' permissions here" if chan
+ @bot.say chan, _("%{user}, you don't have '%{command}' permissions here") %
+ {:user=>user, :command=>cmdtxt} if chan
return false
end
end
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index a1762988..7cedc11e 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -169,7 +169,7 @@ module Irc
string
end
def desc
- "#{@desc} [valid values are: " + values.join(", ") + "]"
+ _("#{@desc} [valid values are: #{values.join(', ')}]")
end
end
@@ -207,7 +207,7 @@ module Irc
}
return
rescue
- error "failed to read conf.yaml: #{$!}"
+ error _("failed to read conf.yaml: #{$!}")
end
end
# if we got here, we need to run the first-run wizard
@@ -238,7 +238,7 @@ module Irc
# return @config[key]
# end
if @config.has_key?(key.to_sym)
- warning "Unregistered lookup #{key.to_sym.inspect}"
+ warning _("Unregistered lookup #{key.to_sym.inspect}")
return @config[key.to_sym]
end
return false
@@ -273,7 +273,7 @@ module Irc
"#{@bot.botclass}/conf.yaml")
@changed = false
rescue => e
- error "failed to write configuration file conf.yaml! #{$!}"
+ error _("failed to write configuration file conf.yaml! #{$!}")
error "#{e.class}: #{e}"
error e.backtrace.join("\n")
end
@@ -301,18 +301,16 @@ module Irc
end
def run()
- puts "First time rbot configuration wizard"
+ puts _("First time rbot configuration wizard")
puts "===================================="
- puts "This is the first time you have run rbot with a config directory of:"
- puts @bot.botclass
- puts "This wizard will ask you a few questions to get you started."
- puts "The rest of rbot's configuration can be manipulated via IRC once"
- puts "rbot is connected and you are auth'd."
+ puts _("This is the first time you have run rbot with a config directory of: #{@bot.botclass}")
+ puts _("This wizard will ask you a few questions to get you started.")
+ puts _("The rest of rbot's configuration can be manipulated via IRC once rbot is connected and you are auth'd.")
puts "-----------------------------------"
return unless @questions
@questions.sort{|a,b| a.order <=> b.order }.each do |q|
- puts q.desc
+ puts _(q.desc)
begin
print q.key.to_s + " [#{q.to_s}]: "
response = STDIN.gets
@@ -320,10 +318,10 @@ module Irc
unless response.empty?
q.set_string response, false
end
- puts "configured #{q.key} => #{q.to_s}"
+ puts _("configured #{q.key} => #{q.to_s}")
puts "-----------------------------------"
rescue ArgumentError => e
- puts "failed to set #{q.key}: #{e.message}"
+ puts _("failed to set #{q.key}: #{e.message}")
retry
end
end
diff --git a/lib/rbot/core/auth.rb b/lib/rbot/core/auth.rb
index e89b5742..d1cdfd42 100644
--- a/lib/rbot/core/auth.rb
+++ b/lib/rbot/core/auth.rb
@@ -59,9 +59,9 @@ class AuthModule < CoreBotModule
next
end
if "+-".include?(x[0])
- warns << ArgumentError.new("please do not use + or - in front of command #{x} when resetting") unless setting
+ warns << ArgumentError.new(_("please do not use + or - in front of command %{command} when resetting") % {:command => x}) unless setting
else
- warns << ArgumentError.new("+ or - expected in front of #{x}") if setting
+ warns << ArgumentError.new(_("+ or - expected in front of %{string}") % {:string => command}) if setting
end
cmds << x
else # parse locations
@@ -74,7 +74,7 @@ class AuthModule < CoreBotModule
when false
locs << x.gsub(/^here$/,'_').gsub(/^private$/,'?')
else
- warns << ArgumentError("#{x} doesn't look like a channel name") unless @bot.server.supports[:chantypes].include?(x[0])
+ warns << ArgumentError("%{string} doesn't look like a channel name" % {:string => x}) unless @bot.server.supports[:chantypes].include?(x[0])
locs << x
end
unless want_more
@@ -83,8 +83,8 @@ class AuthModule < CoreBotModule
end
end
}
- warns << "trailing comma" if want_more
- warns << "you probably forgot a comma" unless last_idx == ar.length - 1
+ warns << _("trailing comma") if want_more
+ warns << _("you probably forgot a comma") unless last_idx == ar.length - 1
return cmds, locs, warns
end
@@ -99,16 +99,16 @@ class AuthModule < CoreBotModule
begin
user = @bot.auth.get_botuser(splits[-1].sub(/^all$/,"everyone"))
rescue
- return m.reply("couldn't find botuser #{splits[-1]}")
+ return m.reply(_("couldn't find botuser %{name}") % {:name => splits[-1]})
end
- return m.reply("you can't change permissions for #{user.username}") if user == @bot.auth.botowner
+ return m.reply(_("you can't change permissions for %{username}") % {:username => user.username}) if user == @bot.auth.botowner
splits.slice!(-2,2) if has_for
cmds, locs, warns = parse_args(splits, setting)
errs = warns.select { |w| w.kind_of?(Exception) }
unless errs.empty?
- m.reply "couldn't satisfy your request: #{errs.join(',')}"
+ m.reply _("couldn't satisfy your request: %{errors}") % {:errors => errs.join(',')}
return
end
@@ -147,13 +147,13 @@ class AuthModule < CoreBotModule
begin
if params[:user].nil?
user = get_botusername_for(m.source)
- return m.reply("you are owner, you can do anything") if user == @bot.auth.botwoner
+ return m.reply(_("you are owner, you can do anything")) if user == @bot.auth.botwoner
else
user = @bot.auth.get_botuser(params[:user].sub(/^all$/,"everyone"))
- return m.reply("owner can do anything") if user.username == "owner"
+ return m.reply(_("owner can do anything")) if user.username == "owner"
end
rescue
- return m.reply("couldn't find botuser #{params[:user]}")
+ return m.reply(_("couldn't find botuser %{name}") % {:name => params[:user]})
end
perm = user.perm
str = []
@@ -161,11 +161,11 @@ class AuthModule < CoreBotModule
next if val.perm.empty?
case k
when :*
- str << "on any channel: "
+ str << _("on any channel: ")
when :"?"
- str << "in private: "
+ str << _("in private: ")
else
- str << "on #{k}: "
+ str << _("on #{k}: ")
end
sub = []
val.perm.each { |cmd, bool|
@@ -175,9 +175,10 @@ class AuthModule < CoreBotModule
str.last << sub.join(', ')
}
if str.empty?
- m.reply "no permissions set for #{user.username}"
+ m.reply _("no permissions set for %{user}") % {:user => user.username}
else
- m.reply "permissions for #{user.username}:: #{str.join('; ')}"
+ m.reply _("permissions for %{user}:: %{permissions}") %
+ { :user => user.username, :permissions => str.join('; ')}
end
end
@@ -190,7 +191,7 @@ class AuthModule < CoreBotModule
end
def welcome(user)
- "welcome, #{get_botusername_for(user)}"
+ _("welcome, %{user}") % {:user => get_botusername_for(user)}
end
def auth_auth(m, params)
@@ -205,10 +206,10 @@ class AuthModule < CoreBotModule
m.reply welcome(m.source)
@bot.auth.set_changed
else
- m.reply "sorry, can't do"
+ m.reply _("sorry, can't do")
end
rescue => e
- m.reply "couldn't login: #{e}"
+ m.reply _("couldn't login: %{exception}") % {:exception => e}
raise
end
end
@@ -217,7 +218,7 @@ class AuthModule < CoreBotModule
u = do_autologin(m.source)
case u.username
when 'everyone'
- m.reply "I couldn't find anything to let you login automatically"
+ m.reply _("I couldn't find anything to let you login automatically")
else
m.reply welcome(m.source)
end
@@ -232,64 +233,67 @@ class AuthModule < CoreBotModule
# if m.public?
# rep << m.source.nick << ", "
# end
- rep << "you are "
- rep << get_botusername_for(m.source).gsub(/^everyone$/, "no one that I know").gsub(/^owner$/, "my boss")
- m.reply rep
+ m.reply _("you are %{who}") % {
+ :who => get_botusername_for(m.source).gsub(
+ /^everyone$/, _("no one that I know")).gsub(
+ /^owner$/, _("my boss"))
+ }
end
def help(cmd, topic="")
case cmd
when "login"
- return "login [<botuser>] [<pass>]: logs in to the bot as botuser <botuser> with password <pass>. When using the full form, you must contact the bot in private. <pass> can be omitted if <botuser> allows login-by-mask and your netmask is among the known ones. if <botuser> is omitted too autologin will be attempted"
+ return _("login [<botuser>] [<pass>]: logs in to the bot as botuser <botuser> with password <pass>. When using the full form, you must contact the bot in private. <pass> can be omitted if <botuser> allows login-by-mask and your netmask is among the known ones. if <botuser> is omitted too autologin will be attempted")
when "whoami"
- return "whoami: names the botuser you're linked to"
+ return _("whoami: names the botuser you're linked to")
when /^permission/
case topic
when "syntax"
- return "a permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix"
+ return _("a permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix")
when "set", "reset", "[re]set", "(re)set"
- return "permissions [re]set <permission> [in <channel>] for <user>: sets or resets the permissions for botuser <user> in channel <channel> (use ? to change the permissions for private addressing)"
+ return _("permissions [re]set <permission> [in <channel>] for <user>: sets or resets the permissions for botuser <user> in channel <channel> (use ? to change the permissions for private addressing)")
when "view"
- return "permissions view [for <user>]: display the permissions for user <user>"
+ return _("permissions view [for <user>]: display the permissions for user <user>")
else
- return "permission topics: syntax, (re)set, view"
+ return _("permission topics: syntax, (re)set, view")
end
when "user"
case topic
when "show"
- return "user show <what> : shows info about the user; <what> can be any of autologin, login-by-mask, netmasks"
+ return _("user show <what> : shows info about the user; <what> can be any of autologin, login-by-mask, netmasks")
when /^(en|dis)able/
- return "user enable|disable <what> : turns on or off <what> (autologin, login-by-mask)"
+ return _("user enable|disable <what> : turns on or off <what> (autologin, login-by-mask)")
when "set"
- return "user set password <blah> : sets the user password to <blah>; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long"
+ return _("user set password <blah> : sets the user password to <blah>; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long")
when "add", "rm"
- return "user add|rm netmask <mask> : adds/removes netmask <mask> from the list of netmasks known to the botuser you're linked to"
+ return _("user add|rm netmask <mask> : adds/removes netmask <mask> from the list of netmasks known to the botuser you're linked to")
when "reset"
- return "user reset <what> : resets <what> to the default values. <what> can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)"
+ return _("user reset <what> : resets <what> to the default values. <what> can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)")
when "tell"
- return "user tell <who> the password for <botuser> : contacts <who> in private to tell him/her the password for <botuser>"
+ return _("user tell <who> the password for <botuser> : contacts <who> in private to tell him/her the password for <botuser>")
when "create"
- return "user create <name> <password> : create botuser named <name> with password <password>. The password can be omitted, in which case a random one will be generated. The <name> should only contain alphanumeric characters and the underscore (_)"
+ return _("user create <name> <password> : create botuser named <name> with password <password>. The password can be omitted, in which case a random one will be generated. The <name> should only contain alphanumeric characters and the underscore (_)")
when "list"
- return "user list : lists all the botusers"
+ return _("user list : lists all the botusers")
when "destroy"
- return "user destroy <botuser> <password> : destroys <botuser>; this function #{Bold}must#{Bold} be called in two steps. On the first call, no password must be specified: <botuser> is then queued for destruction. On the second call, you must specify the correct password for <botuser>, and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy <botuser>+"
+ return _("user destroy <botuser> <password> : destroys <botuser>; this function %{highlight}must%{highlight} be called in two steps. On the first call, no password must be specified: <botuser> is then queued for destruction. On the second call, you must specify the correct password for <botuser>, and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy <botuser>+") % {:highlight => Bold}
else
- return "user topics: show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy"
+ return _("user topics: show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy")
end
when "auth"
- return "auth <masterpassword>: log in as the bot owner; other commands: login, whoami, permission syntax, permissions [re]set, permissions view, user"
+ return _("auth <masterpassword>: log in as the bot owner; other commands: login, whoami, permission syntax, permissions [re]set, permissions view, user")
else
- return "auth commands: auth, login, whoami, permission[s], user"
+ return _("auth commands: auth, login, whoami, permission[s], user")
end
end
def need_args(cmd)
- "sorry, I need more arguments to #{cmd}"
+ _("sorry, I need more arguments to %{command}") % {:command => cmd}
end
def not_args(cmd, *stuff)
- "I can only #{cmd} these: #{stuff.join(', ')}"
+ _("I can only %{command} these: %{arguments}") %
+ {:command => cmd, :arguments => stuff.join(', ')}
end
def set_prop(botuser, prop, val)
@@ -319,7 +323,8 @@ class AuthModule < CoreBotModule
has_for = splits[-2] == "for"
butarget = @bot.auth.get_botuser(splits[-1]) if has_for
- return m.reply("you can't mess with #{butarget.username}") if butarget == @bot.auth.botowner && botuser != butarget
+ return m.reply(_("you can't mess with %{user}") % {:user => butarget.username}) \
+ if butarget == @bot.auth.botowner && botuser != butarget
splits.slice!(-2,2) if has_for
bools = [:autologin, :"login-by-mask"]
@@ -331,18 +336,21 @@ class AuthModule < CoreBotModule
case cmd.to_sym
when :show
- return "you can't see the properties of #{butarget.username}" if botuser != butarget and !botuser.permit?("auth::show::other")
+ return _("you can't see the properties of %{user}") %
+ {:user => butarget.username} if botuser != butarget &&
+ !botuser.permit?("auth::show::other")
case splits[1]
when nil, "all"
props = can_reset
when "password"
if botuser != butarget
- return m.reply("no way I'm telling you the master password!") if butarget == @bot.auth.botowner
- return m.reply("you can't ask for someone else's password")
+ return m.reply(_("no way I'm telling you the master password!")) if butarget == @bot.auth.botowner
+ return m.reply(_("you can't ask for someone else's password"))
end
- return m.reply("c'mon, you can't be asking me seriously to tell you the password in public!") if m.public?
- return m.reply("the password for #{butarget.username} is #{butarget.password}")
+ return m.reply(_("c'mon, you can't be asking me seriously to tell you the password in public!")) if m.public?
+ return m.reply(_("the password for %{user} is %{password}")) %
+ { :user => butarget.username, :password => butarget.password }
else
props = splits[1..-1]
end
@@ -354,23 +362,24 @@ class AuthModule < CoreBotModule
next if k == :password
case k
when *bools
- str << "can"
- str.last << "not" unless ask_bool_prop(butarget, k)
- str.last << " #{k}"
+ if ask_bool_prop(butarget, k)
+ str << _("can %{action}") % {:action => k}
+ else
+ str << _("can not %{action}") % {:action => k}
+ end
when :netmasks
- str << "knows "
if butarget.netmasks.empty?
- str.last << "no netmasks"
+ str << _("knows no netmasks")
else
- str.last << butarget.netmasks.join(", ")
+ str << _("knows %{netmasks}") % {:netmasks => butarget.netmasks.join(", ")}
end
end
}
return m.reply("#{butarget.username} #{str.join('; ')}")
when :enable, :disable
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::other::default")
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")
+ return m.reply(_("you can't change the default user")) if butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::other::default")
+ return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if butarget != botuser && !botuser.permit?("auth::edit::other")
return m.reply(need_args(cmd)) unless splits[1]
things = []
@@ -385,17 +394,21 @@ class AuthModule < CoreBotModule
end
}
- m.reply "I ignored #{skipped.join(', ')} because " + not_args(cmd, *bools) unless skipped.empty?
+ m.reply(_("I ignored %{things} because %{reason}") % {
+ :things => skipped.join(', '),
+ :reason => not_args(cmd, *bools)}) unless skipped.empty?
if things.empty?
- m.reply "I haven't changed anything"
+ m.reply _("I haven't changed anything")
else
@bot.auth.set_changed
return auth_manage_user(m, {:data => ["show"] + things + ["for", butarget.username] })
end
when :set
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")
+ return m.reply(_("you can't change the default user")) if
+ butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::default")
+ return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if
+ butarget != botuser && !botuser.permit?("auth::edit::other")
return m.reply(need_args(cmd)) unless splits[1]
arg = splits[1].to_sym
@@ -403,15 +416,17 @@ class AuthModule < CoreBotModule
argarg = splits[2]
return m.reply(need_args([cmd, splits[1]].join(" "))) unless argarg
if arg == :password && m.public?
- return m.reply("is that a joke? setting the password in public?")
+ return m.reply(_("is that a joke? setting the password in public?"))
end
set_prop(butarget, arg, argarg)
@bot.auth.set_changed
auth_manage_user(m, {:data => ["show", arg, "for", butarget.username] })
when :reset
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")
+ return m.reply(_("you can't change the default user")) if
+ butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::default")
+ return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if
+ butarget != botuser && !botuser.permit?("auth::edit::other")
return m.reply(need_args(cmd)) unless splits[1]
things = []
@@ -426,22 +441,28 @@ class AuthModule < CoreBotModule
end
}
- m.reply "I ignored #{skipped.join(', ')} because " + not_args(cmd, *can_reset) unless skipped.empty?
+ m.reply(_("I ignored %{things} because %{reason}") %
+ { :things => skipped.join(', '),
+ :reason => not_args(cmd, *can_reset)}) unless skipped.empty?
if things.empty?
- m.reply "I haven't changed anything"
+ m.reply _("I haven't changed anything")
else
@bot.auth.set_changed
- @bot.say m.source, "the password for #{butarget.username} is now #{butarget.password}" if things.include?("password")
+ @bot.say(m.source, _("the password for %{user} is now %{password}") %
+ {:user => butarget.username, :password => butarget.password}) if
+ things.include?("password")
return auth_manage_user(m, {:data => (["show"] + things - ["password"]) + ["for", butarget.username]})
end
when :add, :rm, :remove, :del, :delete
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")
+ return m.reply(_("you can't change the default user")) if
+ butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::default")
+ return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if
+ butarget != botuser && !botuser.permit?("auth::edit::other")
arg = splits[1]
if arg.nil? or arg !~ /netmasks?/ or splits[2].nil?
- return m.reply("I can only add/remove netmasks. See +help user add+ for more instructions")
+ return m.reply(_("I can only add/remove netmasks. See +help user add+ for more instructions"))
end
method = cmd.to_sym == :add ? :add_netmask : :delete_netmask
@@ -460,7 +481,7 @@ class AuthModule < CoreBotModule
return auth_manage_user(m, {:data => ["show", "netmasks", "for", butarget.username] })
else
- m.reply "sorry, I don't know how to #{m.message}"
+ m.reply _("sorry, I don't know how to %{request}") % {:request => m.message}
end
end
@@ -469,27 +490,28 @@ class AuthModule < CoreBotModule
begin
botuser = @bot.auth.get_botuser(params[:botuser])
rescue
- return m.reply("coudln't find botuser #{params[:botuser]})")
+ return m.reply(_("couldn't find botuser %{user}") % {:user => params[:botuser]})
end
- m.reply "I'm not telling the master password to anyway, pal" if botuser == @bot.auth.botowner
- msg = "the password for botuser #{botuser.username} is #{botuser.password}"
+ m.reply(_("I'm not telling the master password to anyway, pal")) if botuser == @bot.auth.botowner
+ msg = _("the password for botuser %{user} is %{password}") %
+ {:user => botuser.username, :password => botuser.password}
@bot.say user, msg
- @bot.say m.source, "I told #{user} that " + msg
+ @bot.say m.source, _("I told %{user} that %{message}") % {:user => user, :message => msg}
end
def auth_create_user(m, params)
name = params[:name]
password = params[:password]
- return m.reply("are you nuts, creating a botuser with a publicly known password?") if m.public? and not password.nil?
+ return m.reply(_("are you nuts, creating a botuser with a publicly known password?")) if m.public? and not password.nil?
begin
bu = @bot.auth.create_botuser(name, password)
@bot.auth.set_changed
rescue => e
- m.reply "failed to create #{name}: #{e}"
+ m.reply(_("failed to create %{user}: %{exception}") % {:user => name, :exception => e})
debug e.inspect + "\n" + e.backtrace.join("\n")
return
end
- m.reply "created botuser #{bu.username}"
+ m.reply(_("created botuser %{user}") % {:user => bu.username})
end
def auth_list_users(m, params)
@@ -497,17 +519,19 @@ class AuthModule < CoreBotModule
list = @bot.auth.save_array.inject([]) { |list, x| list << x[:username] } - ['everyone', 'owner']
if defined?(@destroy_q)
list.map! { |x|
- @destroy_q.include?(x) ? x + " (queued for destruction)" : x
+ @destroy_q.include?(x) ? x + _(" (queued for destruction)") : x
}
end
- return m.reply("I have no botusers other than the default ones") if list.empty?
- return m.reply("botuser#{'s' if list.length > 1}: #{list.join(', ')}")
+ return m.reply(_("I have no botusers other than the default ones")) if list.empty?
+ return m.reply(n_("botuser: %{list}", "botusers: %{list}", list.length) %
+ {:list => list.join(', ')})
end
def auth_destroy_user(m, params)
@destroy_q = [] unless defined?(@destroy_q)
buname = params[:name]
- return m.reply("You can't destroy #{buname}") if ["everyone", "owner"].include?(buname)
+ return m.reply(_("You can't destroy %{user}") % {:user => buname}) if
+ ["everyone", "owner"].include?(buname)
cancel = m.message.split[1] == 'cancel'
password = params[:password]
@@ -517,30 +541,32 @@ class AuthModule < CoreBotModule
h
}
- return m.reply("no such botuser #{buname}") unless buser_hash.keys.include?(buname)
+ return m.reply(_("no such botuser %{user}") % {:user=>buname}) unless
+ buser_hash.keys.include?(buname)
if cancel
if @destroy_q.include?(buname)
@destroy_q.delete(buname)
- m.reply "#{buname} removed from the destruction queue"
+ m.reply(_("%{user} removed from the destruction queue") % {:user=>buname})
else
- m.reply "#{buname} was not queued for destruction"
+ m.reply(_("%{user} was not queued for destruction") % {:user=>buname})
end
return
end
if password.nil?
if @destroy_q.include?(buname)
- rep = "#{buname} already queued for destruction"
+ return m.reply(_("%{user} already queued for destruction, use %{highlight}user destroy %{user} <password>%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})
else
@destroy_q << buname
- rep = "#{buname} queued for destruction"
+ return m.reply(_("%{user} queued for destruction, use %{highlight}user destroy %{user} <password>%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})
end
- return m.reply(rep + ", use #{Bold}user destroy #{buname} <password>#{Bold} to destroy it")
else
begin
- return m.reply("#{buname} is not queued for destruction yet") unless @destroy_q.include?(buname)
- return m.reply("wrong password for #{buname}") unless buser_hash[buname][:password] == password
+ return m.reply(_("%{user} is not queued for destruction yet") %
+ {:user=>buname}) unless @destroy_q.include?(buname)
+ return m.reply(_("wrong password for %{user}") %
+ {:user=>buname}) unless buser_hash[buname][:password] == password
buser_array.delete_if { |u|
u[:username] == buname
}
@@ -548,9 +574,9 @@ class AuthModule < CoreBotModule
@bot.auth.load_array(buser_array, true)
@bot.auth.set_changed
rescue => e
- return m.reply("failed: #{e}")
+ return m.reply(_("failed: %{exception}") % {:exception => e})
end
- return m.reply("botuser #{buname} destroyed")
+ return m.reply(_("botuser %{user} destroyed") % {:user => buname})
end
end
@@ -558,7 +584,8 @@ class AuthModule < CoreBotModule
def auth_copy_ren_user(m, params)
source = Auth::BotUser.sanitize_username(params[:source])
dest = Auth::BotUser.sanitize_username(params[:dest])
- return m.reply("please don't touch the default users") if (["everyone", "owner"] | [source, dest]).length < 4
+ return m.reply(_("please don't touch the default users")) unless
+ (["everyone", "owner"] & [source, dest]).empty?
buser_array = @bot.auth.save_array
buser_hash = buser_array.inject({}) { |h, u|
@@ -566,8 +593,10 @@ class AuthModule < CoreBotModule
h
}
- return m.reply("no such botuser #{source}") unless buser_hash.keys.include?(source)
- return m.reply("botuser #{dest} exists already") if buser_hash.keys.include?(dest)
+ return m.reply(_("no such botuser %{source}") % {:source=>source}) unless
+ buser_hash.keys.include?(source)
+ return m.reply(_("botuser %{dest} exists already") % {:dest=>dest}) if
+ buser_hash.keys.include?(dest)
copying = m.message.split[1] == "copy"
begin
@@ -585,10 +614,12 @@ class AuthModule < CoreBotModule
@bot.auth.load_array(buser_array, true)
@bot.auth.set_changed
rescue => e
- return m.reply("failed: #{e}")
+ return m.reply(_("failed: %{exception}") % {:exception=>e})
end
- return m.reply("botuser #{source} copied to #{dest}") if copying
- return m.reply("botuser #{source} renamed to #{dest}")
+ return m.reply(_("botuser %{source} copied to %{dest}") %
+ {:source=>source, :dest=>dest}) if copying
+ return m.reply(_("botuser %{source} renamed to %{dest}") %
+ {:source=>source, :dest=>dest})
end
@@ -606,7 +637,7 @@ class AuthModule < CoreBotModule
what.delete("all")
- m.reply "selecting data to export ..."
+ m.reply _("selecting data to export ...")
buser_array = @bot.auth.save_array
buser_hash = buser_array.inject({}) { |h, u|
@@ -622,7 +653,7 @@ class AuthModule < CoreBotModule
}
end
- m.reply "preparing data for export ..."
+ m.reply _("preparing data for export ...")
begin
yaml_hash = {}
we_want.each { |k, val|
@@ -645,23 +676,23 @@ class AuthModule < CoreBotModule
}
}
rescue => e
- m.reply "failed to prepare data: #{e}"
+ m.reply _("failed to prepare data: %{exception}") % {:exception=>e}
debug e.backtrace.dup.unshift(e.inspect).join("\n")
return
end
- m.reply "exporting to #{exportfile} ..."
+ m.reply _("exporting to %{file} ...") % {:file=>exportfile}
begin
# m.reply yaml_hash.inspect
File.open(exportfile, "w") do |file|
file.puts YAML::dump(yaml_hash)
end
rescue => e
- m.reply "failed to export users: #{e}"
+ m.reply _("failed to export users: %{exception}") % {:exception=>e}
debug e.backtrace.dup.unshift(e.inspect).join("\n")
return
end
- m.reply "done"
+ m.reply _("done")
end
def auth_import(m, params)
@@ -678,18 +709,18 @@ class AuthModule < CoreBotModule
what.delete("all")
- m.reply "reading #{importfile} ..."
+ m.reply _("reading %{file} ...") % {:file=>importfile}
begin
yaml_hash = YAML::load_file(importfile)
rescue => e
- m.reply "failed to import from: #{e}"
+ m.reply _("failed to import from: %{exception}") % {:exception=>e}
debug e.backtrace.dup.unshift(e.inspect).join("\n")
return
end
# m.reply yaml_hash.inspect
- m.reply "selecting data to import ..."
+ m.reply _("selecting data to import ...")
if what.empty?
we_want = yaml_hash
@@ -699,7 +730,7 @@ class AuthModule < CoreBotModule
}
end
- m.reply "parsing data from import ..."
+ m.reply _("parsing data from import ...")
buser_hash = {}
@@ -719,7 +750,7 @@ class AuthModule < CoreBotModule
}
}
rescue => e
- m.reply "failed to parse data: #{e}"
+ m.reply _("failed to parse data: %{exception}") % {:exception=>e}
debug e.backtrace.dup.unshift(e.inspect).join("\n")
return
end
@@ -739,7 +770,7 @@ class AuthModule < CoreBotModule
@bot.auth.load_array(new_buser_array, true)
@bot.auth.set_changed
- m.reply "done"
+ m.reply _("done")
end
end
diff --git a/lib/rbot/core/basics.rb b/lib/rbot/core/basics.rb
index a1720b7a..bd37839c 100644
--- a/lib/rbot/core/basics.rb
+++ b/lib/rbot/core/basics.rb
@@ -104,37 +104,38 @@ class BasicsModule < CoreBotModule
def help(cmd, topic="")
case cmd
when "quit"
- return "quit [<message>] => quit IRC with message <message>"
+ _("quit [<message>] => quit IRC with message <message>")
when "restart"
- return "restart => completely stop and restart the bot (including reconnect)"
+ _("restart => completely stop and restart the bot (including reconnect)")
when "join"
- return "join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{myself} also responds to invites if you have the required access level"
+ _("join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{myself} also responds to invites if you have the required access level")
when "part"
- return "part <channel> => part channel <channel>"
+ _("part <channel> => part channel <channel>")
when "hide"
- return "hide => part all channels"
+ _("hide => part all channels")
when "nick"
- return "nick <nick> => attempt to change nick to <nick>"
+ _("nick <nick> => attempt to change nick to <nick>")
when "say"
- return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"
+ _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
when "action"
- return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"
+ _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
when "quiet"
- return "quiet [in here|<channel>] => with no arguments, stop speaking in all channels, if \"in here\", stop speaking in this channel, or stop speaking in <channel>"
+ _("quiet [in here|<channel>] => with no arguments, stop speaking in all channels, if \"in here\", stop speaking in this channel, or stop speaking in <channel>")
when "talk"
- return "talk [in here|<channel>] => with no arguments, resume speaking in all channels, if \"in here\", resume speaking in this channel, or resume speaking in <channel>"
+ _("talk [in here|<channel>] => with no arguments, resume speaking in all channels, if \"in here\", resume speaking in this channel, or resume speaking in <channel>")
when "version"
- return "version => describes software version"
+ _("version => describes software version")
when "ping"
- return "ping => replies with a pong"
+ _("ping => replies with a pong")
when "mode"
- return "mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>"
+ _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
# when "botsnack"
# return "botsnack => reward #{myself} for being good"
# when "hello"
# return "hello|hi|hey|yo [#{myself}] => greet the bot"
else
- return "#{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk, version, ping, mode"#, botsnack, hello"
+ _("%{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk,version, ping, mode") % {:name=>name}
+ #, botsnack, hello
end
end
end
diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb
index 9de7a861..30d90c73 100644
--- a/lib/rbot/core/config.rb
+++ b/lib/rbot/core/config.rb
@@ -22,7 +22,7 @@ class ConfigModule < CoreBotModule
modules.push key unless modules.include?(name)
end
if modules.empty?
- m.reply "no such module #{params[:module]}"
+ m.reply _("no such module %{module}") % {:module => params[:module]}
else
m.reply modules.join(", ")
end
@@ -38,7 +38,7 @@ class ConfigModule < CoreBotModule
def handle_get(m, params)
key = params[:key].to_s.intern
unless @bot.config.items.has_key?(key)
- m.reply "no such config key #{key}"
+ m.reply _("no such config key %{key}") % {:key => key}
return
end
return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
@@ -49,7 +49,7 @@ class ConfigModule < CoreBotModule
def handle_desc(m, params)
key = params[:key].to_s.intern
unless @bot.config.items.has_key?(key)
- m.reply "no such config key #{key}"
+ m.reply _("no such config key %{key}") % {:key => key}
end
puts @bot.config.items[key].inspect
m.reply "#{key}: #{@bot.config.items[key].desc}"
@@ -58,34 +58,34 @@ class ConfigModule < CoreBotModule
def handle_unset(m, params)
key = params[:key].to_s.intern
unless @bot.config.items.has_key?(key)
- m.reply "no such config key #{key}"
+ m.reply _("no such config key %{key}") % {:key => key}
end
return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
@bot.config.items[key].unset
handle_get(m, params)
- m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart
- m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan
+ m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart
+ m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan
end
def handle_set(m, params)
key = params[:key].to_s.intern
value = params[:value].join(" ")
unless @bot.config.items.has_key?(key)
- m.reply "no such config key #{key}" unless params[:silent]
+ m.reply _("no such config key %{key}") % {:key => key} unless params[:silent]
return false
end
return false if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
begin
@bot.config.items[key].set_string(value)
rescue ArgumentError => e
- m.reply "failed to set #{key}: #{e.message}" unless params[:silent]
+ m.reply _("failed to set %{key}: %{error}") % {:key => key, :error => e.message} unless params[:silent]
return false
end
if @bot.config.items[key].requires_restart
- m.reply "this config change will take effect on the next restart" unless params[:silent]
+ m.reply _("this config change will take effect on the next restart") unless params[:silent]
return :restart
elsif @bot.config.items[key].requires_rescan
- m.reply "this config change will take effect on the next rescan" unless params[:silent]
+ m.reply _("this config change will take effect on the next rescan") unless params[:silent]
return :rescan
else
m.okay unless params[:silent]
@@ -97,46 +97,46 @@ class ConfigModule < CoreBotModule
key = params[:key].to_s.intern
value = params[:value]
unless @bot.config.items.has_key?(key)
- m.reply "no such config key #{key}"
+ m.reply _("no such config key %{key}") % {:key => key}
return
end
unless @bot.config.items[key].kind_of?(BotConfigArrayValue)
- m.reply "config key #{key} is not an array"
+ m.reply _("config key %{key} is not an array") % {:key => key}
return
end
return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
begin
@bot.config.items[key].add(value)
rescue ArgumentError => e
- m.reply "failed to add #{value} to #{key}: #{e.message}"
+ m.reply _("failed to add %{value} to %{key}: %{error}") % {:value => value, :key => key, :error => e.message}
return
end
handle_get(m,{:key => key})
- m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart
- m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan
+ m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart
+ m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan
end
def handle_rm(m, params)
key = params[:key].to_s.intern
value = params[:value]
unless @bot.config.items.has_key?(key)
- m.reply "no such config key #{key}"
+ m.reply _("no such config key %{key}") % {:key => key}
return
end
unless @bot.config.items[key].kind_of?(BotConfigArrayValue)
- m.reply "config key #{key} is not an array"
+ m.reply _("config key %{key} is not an array") % {:key => key}
return
end
return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
begin
@bot.config.items[key].rm(value)
rescue ArgumentError => e
- m.reply "failed to remove #{value} from #{key}: #{e.message}"
+ m.reply _("failed to remove %{value} from %{key}: %{error}") % {:value => value, :key => key, :error => e.message}
return
end
handle_get(m,{:key => key})
- m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart
- m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan
+ m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart
+ m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan
end
def bot_save(m, param)
@@ -145,11 +145,11 @@ class ConfigModule < CoreBotModule
end
def bot_rescan(m, param)
- m.reply "saving ..."
+ m.reply _("saving ...")
@bot.save
- m.reply "rescanning ..."
+ m.reply _("rescanning ...")
@bot.rescan
- m.reply "done. #{@bot.plugins.status(true)}"
+ m.reply _("done. %{plugin_status}") % {:plugin_status => @bot.plugins.status(true)}
end
def bot_nick(m, param)
@@ -168,7 +168,7 @@ class ConfigModule < CoreBotModule
# end
def bot_version(m, param)
- m.reply "I'm a v. #{$version} rubybot, (c) Tom Gilbert and the rbot development team - http://linuxbrit.co.uk/rbot/"
+ m.reply _("I'm a v. %{version} rubybot, (c) Tom Gilbert and the rbot development team - http://linuxbrit.co.uk/rbot/") % {:version => $version}
end
def handle_help(m, params)
@@ -180,32 +180,32 @@ class ConfigModule < CoreBotModule
when "config"
case topic
when ""
- "config-related tasks: config topics, save, rescan"
+ _("config-related tasks: config topics, save, rescan")
when "list"
- "config list => list configuration modules, config list <module> => list configuration keys for module <module>"
+ _("config list => list configuration modules, config list <module> => list configuration keys for module <module>")
when "get"
- "config get <key> => get configuration value for key <key>"
+ _("config get <key> => get configuration value for key <key>")
when "unset"
- "reset key <key> to the default"
+ _("reset key <key> to the default")
when "set"
- "config set <key> <value> => set configuration value for key <key> to <value>"
+ _("config set <key> <value> => set configuration value for key <key> to <value>")
when "desc"
- "config desc <key> => describe what key <key> configures"
+ _("config desc <key> => describe what key <key> configures")
when "add"
- "config add <value> to <key> => add value <value> to key <key> if <key> is an array"
+ _("config add <value> to <key> => add value <value> to key <key> if <key> is an array")
when "rm"
- "config rm <value> from <key> => remove value <value> from key <key> if <key> is an array"
+ _("config rm <value> from <key> => remove value <value> from key <key> if <key> is an array")
else
- "config module - bot configuration. usage: list, desc, get, set, unset, add, rm"
+ _("config module - bot configuration. usage: list, desc, get, set, unset, add, rm")
# else
# "no help for config #{topic}"
end
when "save"
- "save => save current dynamic data and configuration"
+ _("save => save current dynamic data and configuration")
when "rescan"
- "rescan => reload modules and static facts"
+ _("rescan => reload modules and static facts")
else
- "config-related tasks: config, save, rescan"
+ _("config-related tasks: config, save, rescan")
end
end
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index f4c1f5bc..1469ac1e 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -90,6 +90,8 @@ fatal "fatal test"
# The following global is used for the improved signal handling.
$interrupted = 0
+require 'rbot/load-gettext'
+
# these first
require 'rbot/rbotconfig'
require 'rbot/config'
@@ -217,7 +219,7 @@ class Bot
:default => [], :wizard => true,
:desc => "What channels the bot should always join at startup. List multiple channels using commas to separate. If a channel requires a password, use a space after the channel name. e.g: '#chan1, #chan2, #secretchan secritpass, #chan3'")
BotConfig.register BotConfigArrayValue.new('irc.ignore_users',
- :default => [],
+ :default => [],
:desc => "Which users to ignore input from. This is mainly to avoid bot-wars triggered by creative people")
BotConfig.register BotConfigIntegerValue.new('core.save_every',
@@ -384,7 +386,7 @@ class Bot
end
# See http://blog.humlab.umu.se/samuel/archives/000107.html
- # for the backgrounding code
+ # for the backgrounding code
if $daemonize
begin
exit if fork
@@ -555,7 +557,7 @@ class Bot
}
}
@client[:nicktaken] = proc { |data|
- new = "#{data[:nick]}_"
+ new = "#{data[:nick]}_"
nickchg new
# If we're setting our nick at connection because our choice was taken,
# we have to fix our nick manually, because there will be no NICK message
@@ -753,7 +755,7 @@ class Bot
quit if $interrupted > 0
realname = @config['irc.name'].clone || 'Ruby bot'
- realname << ' ' + COPYRIGHT_NOTICE if @config['irc.name_copyright']
+ realname << ' ' + COPYRIGHT_NOTICE if @config['irc.name_copyright']
@socket.emergency_puts "PASS " + @config['server.password'] if @config['server.password']
@socket.emergency_puts "NICK #{@config['irc.nick']}\nUSER #{@config['irc.user']} 4 #{@socket.server_uri.host} :#{realname}"
diff --git a/lib/rbot/load-gettext.rb b/lib/rbot/load-gettext.rb
new file mode 100644
index 00000000..c8448bc6
--- /dev/null
+++ b/lib/rbot/load-gettext.rb
@@ -0,0 +1,113 @@
+# load gettext module and provide fallback in case of failure
+
+require 'stringio'
+
+# try to load gettext, or provide fake getttext functions
+begin
+ require 'gettext'
+ include GetText
+ bindtextdomain 'rbot'
+
+ module GetText
+ # patch for ruby-gettext 1.9.0 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
+ def bound_targets(klass) # :nodoc:
+ ret = []
+ ary = klass.name.split(/::/)
+ while(v = ary.shift)
+ begin
+ ret.unshift(((ret.size == 0) ?
+ Object.const_get(v) : ret[0].const_get(v)))
+ rescue NameError
+ # when an anonymous module is encountered, only the previous modules
+ # are returned
+ break
+ end
+ end
+ ((ret + klass.ancestors + [GetText]) & @@__textdomainmanagers.keys).uniq
+ end
+ end
+
+ debug 'using ruby-gettext'
+ gettext_info = StringIO.new
+ current_textdomain_info(:out=>gettext_info)
+ gettext_info.string.each_line {|l| debug l}
+
+rescue LoadError
+ warn 'ruby-gettext package not available; translations are disabled'
+
+ # dummy functions that return msg_id without translation
+ def _(s)
+ s
+ end
+
+ def N_(s)
+ s
+ end
+
+ def n_(s_single, s_plural, n)
+ n > 1 ? s_plural : s_single
+ end
+
+ def s_(*args)
+ args[0]
+ end
+
+ # the following extension to String#% is from ruby-gettext's string.rb file.
+ # it needs to be included in the fallback since the source already use this form
+
+=begin
+ string.rb - Extension for String.
+
+ Copyright (C) 2005,2006 Masao Mutoh
+
+ You may redistribute it and/or modify it under the same
+ license terms as Ruby.
+=end
+
+ # Extension for String class.
+ #
+ # String#% method which accept "named argument". The translator can know
+ # the meaning of the msgids using "named argument" instead of %s/%d style.
+ class String
+ alias :_old_format_m :% # :nodoc:
+
+ # call-seq:
+ # %(arg)
+ # %(hash)
+ #
+ # Format - Uses str as a format specification, and returns the result of applying it to arg.
+ # If the format specification contains more than one substitution, then arg must be
+ # an Array containing the values to be substituted. See Kernel::sprintf for details of the
+ # format string. This is the default behavior of the String class.
+ # * arg: an Array or other class except Hash.
+ # * Returns: formatted String
+ #
+ # (e.g.) "%s, %s" % ["Masao", "Mutoh"]
+ #
+ # Also you can use a Hash as the "named argument". This is recommanded way for Ruby-GetText
+ # because the translators can understand the meanings of the msgids easily.
+ # * hash: {:key1 => value1, :key2 => value2, ... }
+ # * Returns: formatted String
+ #
+ # (e.g.) "%{firstname}, %{familyname}" % {:firstname => "Masao", :familyname => "Mutoh"}
+ def %(args)
+ if args.kind_of?(Hash)
+ ret = dup
+ args.each {|key, value|
+ ret.gsub!(/\%\{#{key}\}/, value.to_s)
+ }
+ ret
+ else
+ ret = gsub(/%\{/, '%%{')
+ begin
+ ret._old_format_m(args)
+ rescue ArgumentError
+ $stderr.puts " The string:#{ret}"
+ $stderr.puts " args:#{args.inspect}"
+ end
+ end
+ end
+ end
+end
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index ab7be40a..ba6175fa 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -234,7 +234,7 @@ module Plugins
# default usage method provided as a utility for simple plugins. The
# MessageMapper uses 'usage' as its default fallback method.
def usage(m, params = {})
- m.reply "incorrect usage, ask for help using '#{@bot.nick}: help #{m.plugin}'"
+ m.reply(_("incorrect usage, ask for help using '%{command}'") % {:command => "#{@bot.nick}: help #{m.plugin}"})
end
end
@@ -471,39 +471,65 @@ module Plugins
end
def status(short=false)
- list = ""
+ output = []
if self.core_length > 0
- list << "#{self.core_length} core module#{'s' if core_length > 1}"
if short
- list << " loaded"
+ output << n_("%{count} core module loaded", "%{count} core modules loaded",
+ self.core_length) % {:count => self.core_length}
else
- list << ": " + core_modules.collect{ |p| p.name}.sort.join(", ")
+ output << n_("%{count} core module: %{list}",
+ "%{count} core modules: %{list}", self.core_length) %
+ { :count => self.core_length,
+ :list => core_modules.collect{ |p| p.name}.sort.join(", ") }
end
else
- list << "no core botmodules loaded"
+ output << _("no core botmodules loaded")
end
# Active plugins first
if(self.length > 0)
- list << "; #{self.length} plugin#{'s' if length > 1}"
if short
- list << " loaded"
+ output << n_("%{count} plugin loaded", "%{count} plugins loaded",
+ self.length) % {:count => self.length}
else
- list << ": " + plugins.collect{ |p| p.name}.sort.join(", ")
+ output << n_("%{count} plugin: %{list}",
+ "%{count} plugins: %{list}", self.length) %
+ { :count => self.length,
+ :list => core_modules.collect{ |p| p.name}.sort.join(", ") }
end
else
- list << "no plugins active"
+ output << "no plugins active"
end
# Ignored plugins next
unless @ignored.empty? or @failures_shown
- list << "; #{Underline}#{@ignored.length} plugin#{'s' if @ignored.length > 1} ignored#{Underline}"
- list << ": use #{Bold}help ignored plugins#{Bold} to see why" unless short
+ if short
+ output << n_("%{highlight}%{count} plugin ignored%{highlight}",
+ "%{highlight}%{count} plugins ignored%{highlight}",
+ @ignored.length) %
+ { :count => @ignored.length, :highlight => Underline }
+ else
+ output << n_("%{highlight}%{count} plugin ignored%{highlight}: use %{bold}%{command}%{bold} to see why",
+ "%{highlight}%{count} plugins ignored%{highlight}: use %{bold}%{command}%{bold} to see why",
+ @ignored.length) %
+ { :count => @ignored.length, :highlight => Underline,
+ :bold => Bold, :command => "help ignored plugins"}
+ end
end
# Failed plugins next
unless @failed.empty? or @failures_shown
- list << "; #{Reverse}#{@failed.length} plugin#{'s' if @failed.length > 1} failed to load#{Reverse}"
- list << ": use #{Bold}help failed plugins#{Bold} to see why" unless short
+ if short
+ output << n_("%{highlight}%{count} plugin failed to load%{highlight}",
+ "%{highlight}%{count} plugins failed to load%{highlight}",
+ @ignored.length) %
+ { :count => @ignored.length, :highlight => Reverse }
+ else
+ output << n_("%{highlight}%{count} plugin failed to load%{highlight}: use %{bold}%{command}%{bold} to see why",
+ "%{highlight}%{count} plugins failed to load%{highlight}: use %{bold}%{command}%{bold} to see why",
+ @ignored.length) %
+ { :count => @ignored.length, :highlight => Reverse,
+ :bold => Bold, :command => "#{Bold}help failed plugins#{Bold}"}
+ end
end
- list
+ output.join '; '
end
# return list of help topics (plugin names)
@@ -526,23 +552,28 @@ module Plugins
case topic
when /fail(?:ed)?\s*plugins?.*(trace(?:back)?s?)?/
# debug "Failures: #{@failed.inspect}"
- return "no plugins failed to load" if @failed.empty?
- return @failed.inject(Array.new) { |list, p|
- list << "#{Bold}#{p[:name]}#{Bold} in #{p[:dir]} failed"
- list << "with error #{p[:reason].class}: #{p[:reason]}"
- list << "at #{p[:reason].backtrace.join(', ')}" if $1 and not p[:reason].backtrace.empty?
- list
+ return _("no plugins failed to load") if @failed.empty?
+ return @failed.collect { |p|
+ _('%{highlight}%{plugin}%{highlight} in %{dir}failed with error %{exception}: %{reason}') % {
+ :highlight => Bold, :plugin => p[:name], :dir => p[:dir],
+ :exception => p[:reason].class, :reason => p[:reason],
+ } + if $1 && !p[:reason].backtrace.empty?
+ _('at %{backtrace}') % {:backtrace => p[:reason].backtrace.join(', ')}
+ else
+ ''
+ end
}.join("\n")
when /ignored?\s*plugins?/
- return "no plugins were ignored" if @ignored.empty?
+ return _('no plugins were ignored') if @ignored.empty?
tmp = Hash.new
@ignored.each do |p|
- reason = p[:loaded] ? 'overruled by previous' : p[:reason].to_s
+ reason = p[:loaded] ? _('overruled by previous') : _(p[:reason].to_s)
((tmp[p[:dir]] ||= Hash.new)[reason] ||= Array.new).push(p[:name])
end
return tmp.map do |dir, reasons|
+ # FIXME get rid of these string concatenations to make gettext easier
s = reasons.map { |r, list|
list.map { |_| _.sub(/\.rb$/, '') }.join(', ') + " (#{r})"
}.join('; ')
@@ -566,7 +597,7 @@ module Plugins
# Nope, let's see if it's a command, and ask for help at the corresponding botmodule
k = key.to_sym
if commands.has_key?(k)
- p = commands[k][:botmodule]
+ p = commands[k][:botmodule]
begin
return p.help(key, params)
rescue Exception => err
diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb
index d6c06782..d1388ce2 100644
--- a/lib/rbot/registry.rb
+++ b/lib/rbot/registry.rb
@@ -16,7 +16,7 @@ module Irc
# work with is @bot.botclass.
def upgrade_data
if File.exist?("#{@bot.botclass}/registry.db")
- log "upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format"
+ log _("upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format")
old = BDB::Hash.open("#{@bot.botclass}/registry.db", nil,
"r+", 0600)
new = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
@@ -36,7 +36,7 @@ module Irc
Dir.mkdir("#{@bot.botclass}/registry") unless File.exist?("#{@bot.botclass}/registry")
env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)# | BDB::TXN_NOSYNC)
dbs = Hash.new
- log "upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format"
+ log _("upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format")
old = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
"r+", 0600, "env" => env)
old.each {|k,v|
@@ -49,13 +49,13 @@ module Irc
dirs.length.times { |i|
dir = dirs[0,i+1].join("/")+"/"
unless File.exist?(dir)
- log "creating subregistry directory #{dir}"
- Dir.mkdir(dir)
+ log _("creating subregistry directory #{dir}")
+ Dir.mkdir(dir)
end
}
end
unless dbs.has_key?(prefix)
- log "creating db #{@bot.botclass}/registry/#{prefix}.db"
+ log _("creating db #{@bot.botclass}/registry/#{prefix}.db")
dbs[prefix] = BDB::CIBtree.open("#{@bot.botclass}/registry/#{prefix}.db",
nil, BDB::CREATE | BDB::EXCL,
0600, "env" => env)
@@ -65,7 +65,7 @@ module Irc
old.close
File.rename("#{@bot.botclass}/plugin_registry.db", "#{@bot.botclass}/plugin_registry.db.old")
dbs.each {|k,v|
- log "closing db #{k}"
+ log _("closing db #{k}")
v.close
}
env.close
@@ -131,7 +131,7 @@ module Irc
dir = dirs[0,i+1].join("/")+"/"
unless File.exist?(dir)
debug "creating subregistry directory #{dir}"
- Dir.mkdir(dir)
+ Dir.mkdir(dir)
end
}
@registry = nil
@@ -179,13 +179,13 @@ module Irc
begin
Marshal.restore(val)
rescue Exception => e
- error "failed to restore marshal data for #{val.inspect}, attempting recovery or fallback to default"
+ error _("failed to restore marshal data for #{val.inspect}, attempting recovery or fallback to default")
debug e
if @recovery
begin
return @recovery.call(val)
rescue Exception => ee
- error "marshal recovery failed, trying default"
+ error _("marshal recovery failed, trying default")
debug ee
end
end