Module: GeoLocale
- Defined in:
- lib/geo_locale.rb,
lib/geo_locale/locale.rb,
lib/geo_locale/version.rb,
lib/geo_locale/country_code.rb more...
Defined Under Namespace
Classes: Config
Constant Summary collapse
- ROOT =
File.("../..", __FILE__)
- LOCALHOST_IP =
"127.0.0.1"
- LOCALE =
{ "lv" => "lv", "lt" => "lt", "ee" => "et", "ru" => "ru", "ie" => "en", # Ireland "gb" => "en", # UK a.k.a Great Britain "uk" => "en", # fallback England "us" => "en", # US&A "pl" => "pl", "de" => "de", "fr" => "fr", "sk" => "sk", "ua" => "uk", "br" => "pt", "fi" => "fi", "dk" => "da", "az" => "az", "ge" => "ka", "ro" => "ro", "md" => "ro" }
- LCID =
{ "lv" => "lv", "lt" => "lt", "ee" => "et", "ru" => "ru", "ie" => "en-ie", # Ireland "gb" => "en-gb", # UK a.k.a Great Britain "uk" => "en-gb", # fallback England "us" => "en-us", # US&A "pl" => "pl", "de" => "de", "fr" => "fr", "sk" => "sk", "ua" => "uk", "br" => "pt-br", "fi" => "fi", "dk" => "da", "az" => "az-az", "ge" => "ka", "ro" => "ro", "md" => "ro-mo" }
- VERSION =
"0.9.5"
- IP_REGEX =
/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
- .configure {|config| ... } ⇒ Object
-
.country_code(ip: "", request_headers: {}) ⇒ Object
ip = “12.12.12.12”.
- .locale(ip: "", country_code: nil, lcid: false, request_headers: {}) ⇒ Object
Class Attribute Details
permalink .config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/geo_locale.rb', line 10 def config @config end |
Class Method Details
permalink .configure {|config| ... } ⇒ Object
15 16 17 18 |
# File 'lib/geo_locale.rb', line 15 def self.configure self.config ||= Config.new yield(config) end |
permalink .country_code(ip: "", request_headers: {}) ⇒ Object
ip = “12.12.12.12”
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/geo_locale/country_code.rb', line 6 def self.country_code(ip: "", request_headers: {}) # ip = "12.12.12.12" if request_headers.present? cloudflare_country_code = cloudflare_country_code(request_headers) return cloudflare_country_code.downcase if cloudflare_country_code.present? && cloudflare_country_code != "XX" end return GeoLocale.config.localhost_country if ip == GeoLocale::LOCALHOST_IP && GeoLocale.config.localhost_country.present? country_code = GeoLocale.geo_ip_try(ip) if country_code.present? return country_code else country_code = GeoLocale.geokit_try(ip) if country_code.present? return country_code else # final fallback, config default return GeoLocale.config.default_country end end end |
permalink .locale(ip: "", country_code: nil, lcid: false, request_headers: {}) ⇒ Object
[View source]
3 4 5 6 |
# File 'lib/geo_locale/locale.rb', line 3 def self.locale (ip: "", country_code: nil, lcid: false, request_headers: {}) country_code ||= GeoLocale.country_code(ip: ip, request_headers: request_headers) GeoLocale.get_locale_or_lcid(country_code: country_code, lcid: lcid) end |