From e73fb21bbc3c947280cb884c8c48d642f8c7f6b2 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 27 Aug 2007 21:47:35 +0000 Subject: Language.from_locale now checks if the corresponding .lang file exist before returning a language string --- lib/rbot/language.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/rbot/language.rb') 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' -- cgit v1.2.3