diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-08-29 15:37:47 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-08-29 15:37:47 +0000 |
commit | 05dfd4e1a0f4e17c23ae7bfeed776c943c9394fe (patch) | |
tree | eeae376a49f61e7cc91e5b9ff9a53148e1d8a5cd | |
parent | 5dc41054c67436ce2d2a14729472d6cb08b9cc37 (diff) |
Flatten out Language module and class
-rw-r--r-- | lib/rbot/ircbot.rb | 2 | ||||
-rw-r--r-- | lib/rbot/language.rb | 80 |
2 files changed, 40 insertions, 42 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 87d4f3eb..17d7ffe7 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -448,7 +448,7 @@ class Bot @logs = Hash.new @plugins = nil - @lang = Language::Language.new(self, @config['core.language']) + @lang = Language.new(self, @config['core.language']) begin @auth = Auth::authmanager diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb index 57e9a6d2..7cf1ceb9 100644 --- a/lib/rbot/language.rb +++ b/lib/rbot/language.rb @@ -8,53 +8,52 @@ # .lang file etc. module Irc -module Language + class Language - # This constant hash holds the mapping - # from long language names to the usual POSIX - # locale specifications - Lang2Locale = { - :english => 'en', - :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' - } + # This constant hash holds the mapping + # from long language names to the usual POSIX + # locale specifications + Lang2Locale = { + :english => 'en', + :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' + } - # Return the shortest language for the current - # GetText locale - def Language.from_locale - return 'english' unless defined?(GetText) - lang = locale.language - if locale.country - str = lang + "_#{locale.country}" - if Lang2Locale.value?(str) - # Get the shortest key in Lang2Locale which maps to the given lang_country - lang_str = Lang2Locale.select { |k, v| v == str }.transpose.first.map { |v| v.to_s }.sort { |a, b| a.length <=> b.length }.first - if File.exist?(File.join(Config::datadir, "languages/#{lang_str}.lang")) - return lang_str + # Return the shortest language for the current + # GetText locale + def Language.from_locale + return 'english' unless defined?(GetText) + lang = locale.language + if locale.country + str = lang + "_#{locale.country}" + if Lang2Locale.value?(str) + # Get the shortest key in Lang2Locale which maps to the given lang_country + lang_str = Lang2Locale.select { |k, v| v == str }.transpose.first.map { |v| v.to_s }.sort { |a, b| a.length <=> b.length }.first + if File.exist?(File.join(Config::datadir, "languages/#{lang_str}.lang")) + return lang_str + end end end - end - # lang_country didn't work, let's try lan - if Lang2Locale.value?(lang) - # Get the shortest key in Lang2Locale which maps to the given lang - lang_str = Lang2Locale.select { |k, v| v == lang }.transpose.first.map { |v| v.to_s }.sort { |a, b| a.length <=> b.length }.first - if File.exist?(File.join(Config::datadir, "/languages/#{lang_str}.lang")) - return lang_str + # lang_country didn't work, let's try lan + if Lang2Locale.value?(lang) + # Get the shortest key in Lang2Locale which maps to the given lang + lang_str = Lang2Locale.select { |k, v| v == lang }.transpose.first.map { |v| v.to_s }.sort { |a, b| a.length <=> b.length }.first + if File.exist?(File.join(Config::datadir, "/languages/#{lang_str}.lang")) + return lang_str + end end + # all else fail, return 'english' + return 'english' end - # all else fail, return 'english' - return 'english' - end - class Language BotConfig.register BotConfigEnumValue.new('core.language', :default => Irc::Language.from_locale, :wizard => true, :values => Proc.new{|bot| @@ -142,4 +141,3 @@ module Language end end -end |