]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Language.from_locale now checks if the corresponding .lang file exist before returnin...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 27 Aug 2007 21:47:35 +0000 (21:47 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 27 Aug 2007 21:47:35 +0000 (21:47 +0000)
lib/rbot/language.rb

index 5fbbfefdec97d65f1075443bda72c544398a3df0..57e9a6d272fcb72fce018578dd4b0eb69e722259 100644 (file)
@@ -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'