summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-25 23:05:32 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-25 23:05:32 +0000
commitb64be129f02b7238030ea2f9e160118894b41174 (patch)
tree7c716e233d2ad026fb6c925f9fe6caba4f38b84b /lib/rbot
parent613eae649ef41568a7c263b51b0ff1819d6b24ba (diff)
gettext support: initial works for language -> locale mappings
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/language.rb37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb
index edb3cafa..e77bb90a 100644
--- a/lib/rbot/language.rb
+++ b/lib/rbot/language.rb
@@ -1,6 +1,32 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: Language module for rbot
+#
+# This module takes care of language handling for rbot:
+# setting the core.language value, loading the appropriate
+# .lang file etc.
+#
module Irc
module Language
+ # This constant has holds the mapping
+ # from long language names to usual POSIX
+ # locale specifications
+ Lang2Locale = {
+ :english => 'en_GB',
+ :british_english => 'en_GB',
+ :american_english => 'en_US',
+ :italian => 'it',
+ :french => 'fr',
+ :german => 'de',
+ :dutch => 'nl',
+ :japanese => 'ja',
+ :russian => 'ru',
+ :traditional_chinese => 'zh_TW',
+ :simplified_chinese => 'zh_CN'
+ }
+
class Language
BotConfig.register BotConfigEnumValue.new('core.language',
:default => "english", :wizard => true,
@@ -16,9 +42,18 @@ module Language
@bot = bot
set_language language
end
- attr_reader :language
+ attr_reader :language, :locale
def set_language(language)
+ l = language.to_s.gsub(/\s+/,'_').intern
+ if Lang2Locale.key?(l)
+ @locale = Lang2Locale[l]
+ debug "locale set to #{@locale}"
+ setlocale(@locale)
+ else
+ warn "Unable to set locale, unknown language #{l}"
+ end
+
file = Config::datadir + "/languages/#{language}.lang"
unless(FileTest.exist?(file))
raise "no such language: #{language} (no such file #{file})"