summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rbot/ircbot.rb3
-rw-r--r--lib/rbot/language.rb15
-rw-r--r--lib/rbot/plugins.rb7
3 files changed, 23 insertions, 2 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 432b61c4..ac7aa829 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -346,7 +346,8 @@ class IrcBot
@httputil = Utils::HttpUtil.new(self)
- @lang = Language::Language.new(@config['core.language'])
+ @plugins = nil
+ @lang = Language::Language.new(self, @config['core.language'])
begin
@auth = Auth::authmanager
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb
index 1a4a889a..edb3cafa 100644
--- a/lib/rbot/language.rb
+++ b/lib/rbot/language.rb
@@ -12,9 +12,11 @@ module Language
:on_change => Proc.new {|bot, v| bot.lang.set_language v},
:desc => "Which language file the bot should use")
- def initialize(language)
+ def initialize(bot, language)
+ @bot = bot
set_language language
end
+ attr_reader :language
def set_language(language)
file = Config::datadir + "/languages/#{language}.lang"
@@ -24,6 +26,17 @@ module Language
@language = language
@file = file
scan
+ return if @bot.plugins.nil?
+ @bot.plugins.core_modules.each { |p|
+ if p.respond_to?('set_language')
+ p.set_language(@language)
+ end
+ }
+ @bot.plugins.plugins.each { |p|
+ if p.respond_to?('set_language')
+ p.set_language(@language)
+ end
+ }
end
def scan
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 8aa75d20..66a7d842 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -88,6 +88,10 @@ module Plugins
connect():: Called when a server is joined successfully, but
before autojoin channels are joined (no params)
+ set_language(String)::
+ Called when the user sets a new language
+ whose name is the given String
+
save:: Called when you are required to save your plugin's
state, if you maintain data between sessions
@@ -111,6 +115,9 @@ module Plugins
@registry = BotRegistryAccessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
@manager.add_botmodule(self)
+ if self.respond_to?('set_language')
+ self.set_language(@bot.lang.language)
+ end
end
def botmodule_class