]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
geoip: massage a few messages
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 20 Jul 2010 08:21:56 +0000 (10:21 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 20 Jul 2010 08:21:56 +0000 (10:21 +0200)
Solve a few gettext issue, and re-introduce the commas around the
region.

data/rbot/plugins/geoip.rb

index 3b7bf75169a4d7e7de883abd5da6bd15a839008f..99ed71eb15b4617d6a865cb3fd93d50b54539d17 100755 (executable)
@@ -183,32 +183,30 @@ class GeoIpPlugin < Plugin
       }
     rescue GeoIP::InvalidHostError, RuntimeError
       if nick
-        return _("#{nick}'s location could not be resolved")
+        return _("%{nick}'s location could not be resolved") % { :nick => nick }
       else
-        return _("#{host} could not be resolved")
+        return _("%{host} could not be resolved") % { :host => host }
       end
     rescue GeoIP::BadAPIError
       return _("The owner configured me to use an API that doesn't exist, bug them!")
     end
 
-    res = _("%{thing} is #{nick ? "from" : "located in"}") % {
-      :thing   => (nick ? nick : Resolv::getaddress(host)),
-      :country => geo[:country]
-    }
-
-    res << " %{city}" % {
-      :city => geo[:city]
-    } unless geo[:city].to_s.empty?
+    location = []
+    location << geo[:city] unless geo[:city].nil_or_empty?
+    location << geo[:region] unless geo[:region].nil_or_empty? or geo[:region] == geo[:city]
+    location << geo[:country] unless geo[:country].nil_or_empty?
 
-    res << " %{region}," % {
-      :region  => geo[:region]
-    } unless geo[:region].to_s.empty? || geo[:region] == geo[:city]
+    if nick
+      res = _("%{nick} is from %{location}")
+    else
+      res = _("%{host} is located in %{location}")
+    end
 
-    res << " %{country}" % {
-      :country => geo[:country]
+    return res % {
+      :nick => nick,
+      :host => host,
+      :location => location.join(', ')
     }
-
-    return res
   end
 end