We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Themes, plugins and other supporting code for the Mephisto Blog.
Clone URL: git://github.com/captproton/mephisto-support.git
100644 95 lines (74 sloc) 2.459 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# $Id: locale.rb,v 1.4 2005/03/02 02:55:46 ianmacd Exp $
#
 
catch :done do
 
  begin
    require 'net/geoip'
  rescue LoadError
    throw :done
  end
 
  module Amazon
 
    # Use of this module requires the use of the GeoIP library from
    # MaxMind[http://www.maxmind.com/]. It also requires the
    # net-geoip[http://www.rubynet.org/modules/net/geoip/] Ruby module to
    # interface with it.
    #
    # Load this library as follows:
    #
    # require 'amazon/locale'
    #
    module Locale
 
      # These constant lists are obviously not complete.
 
      # ISO 3166[http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/iso_3166-1_decoding_table.html]
      # codes of countries likely to want to shop in the CA locale.
      #
      CA = %w[ ca ]
 
      # ISO 3166 codes of countries likely to want to shop in the DE locale.
      #
      DE = %w[ at ch de ]
 
      # ISO 3166 codes of countries likely to want to shop in the FR locale.
      #
      FR = %w[ fr ]
 
      # ISO 3166 codes of countries likely to want to shop in the JP locale.
      #
      JP = %w[ jp ]
 
      # ISO 3166 codes of countries likely to want to shop in the UK locale.
      #
      UK = %w[ ad al ba be cy cz dk ee es fi fo gi gr gl ie is it li lt lu
   lv mk mt nl no pl pt ro se si sk sm uk ]
 
      # ISO 3166 codes of countries likely to want to shop in the US locale.
      # Any countries not explicitly listed above default to the US locale.
      #
      US = %w[ mx us ]
 
 
      def Locale.localise(code)
  code.downcase!
 
  return 'ca' if CA.include? code
  return 'de' if DE.include? code
  return 'fr' if FR.include? code
  return 'jp' if JP.include? code
  return 'uk' if UK.include? code
 
  'us'
      end
      private_class_method :localise
 
 
      # This will attempt to return a reasonable locale (*ca*, *de*, *fr*,
      # *jp*, *uk* or *us*) to use for _host_.
      #
      # For example:
      #
      # get_locale_by_name('xs1.xs4all.nl') => "uk"
      #
      def Locale.get_locale_by_name(host)
  localise(Net::GeoIP.new.country_code_by_name(host))
      end
 
      # This will attempt to return a reasonable locale (*ca*, *de*, *fr*,
      # *jp*, *uk* or *us*) to use for the IP address _addr_.
      #
      # For example:
      #
      # get_locale_by_addr('217.110.207.55') => "de"
      #
      def Locale.get_locale_by_addr(address)
  localise(Net::GeoIP.new.country_code_by_addr(address))
      end
 
    end
  end
 
end