diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-08-27 21:47:35 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-08-27 21:47:35 +0000 |
commit | e73fb21bbc3c947280cb884c8c48d642f8c7f6b2 (patch) | |
tree | 2675155338a3c256ea26bf712d68d5d4a844acb5 | |
parent | ce62f69cacce0abb242505a85fac5badde0440d5 (diff) |
Language.from_locale now checks if the corresponding .lang file exist before returning a language string
-rw-r--r-- | lib/rbot/language.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb index 5fbbfefd..57e9a6d2 100644 --- a/lib/rbot/language.rb +++ b/lib/rbot/language.rb @@ -36,13 +36,19 @@ module Language str = lang + "_#{locale.country}" if Lang2Locale.value?(str) # Get the shortest key in Lang2Locale which maps to the given lang_country - return Lang2Locale.select { |k, v| v == str }.transpose.first.map { |v| v.to_s }.sort { |a, b| a.length <=> b.length }.first + 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 # 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 - return Lang2Locale.select { |k, v| v == lang }.transpose.first.map { |v| v.to_s }.sort { |a, b| a.length <=> b.length }.first + 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' |