diff options
Diffstat (limited to 'lib/rbot/language.rb')
-rw-r--r-- | lib/rbot/language.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb index ee6746d6..d48607b8 100644 --- a/lib/rbot/language.rb +++ b/lib/rbot/language.rb @@ -1,21 +1,24 @@ module Irc class Language - BotConfig.register('core.language', - :default => "english", :type => :enum, + BotConfig.register BotConfigEnumValue.new('core.language', + :default => "english", :wizard => true, :values => Dir.new(Config::DATADIR + "/languages").collect {|f| f =~ /\.lang$/ ? f.gsub(/\.lang$/, "") : nil }.compact, + :on_change => Proc.new {|bot, v| bot.lang.set_language v}, :desc => "Which language file the bot should use") - def initialize(language, file="") - @language = language - if file.empty? - file = Config::DATADIR + "/languages/#{@language}.lang" - end + def initialize(language) + set_language language + end + + def set_language(language) + file = Config::DATADIR + "/languages/#{language}.lang" unless(FileTest.exist?(file)) - raise "no such language: #{@language} (no such file #{file})" + raise "no such language: #{language} (no such file #{file})" end + @language = language @file = file scan end |