world-flags 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -5
- data/README.md +41 -6
- data/VERSION +1 -1
- data/db/GeoIP.dat +0 -0
- data/lib/world_flags/helper/geo.rb +14 -8
- data/lib/world_flags/helper/locale.rb +5 -1
- data/lib/world_flags/util/config.rb +9 -1
- data/spec/data/GeoIP.dat +0 -0
- data/world-flags.gemspec +4 -2
- metadata +5 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -32,12 +32,10 @@ GEM
|
|
32
32
|
builder (3.0.0)
|
33
33
|
diff-lcs (1.1.3)
|
34
34
|
erubis (2.7.0)
|
35
|
+
geoip (1.1.2)
|
35
36
|
git (1.2.5)
|
36
37
|
hashie (1.2.0)
|
37
38
|
hike (1.2.1)
|
38
|
-
httparty (0.8.1)
|
39
|
-
multi_json
|
40
|
-
multi_xml
|
41
39
|
i18n (0.6.0)
|
42
40
|
jeweler (1.8.3)
|
43
41
|
bundler (~> 1.0)
|
@@ -52,7 +50,6 @@ GEM
|
|
52
50
|
treetop (~> 1.4.8)
|
53
51
|
mime-types (1.17.2)
|
54
52
|
multi_json (1.1.0)
|
55
|
-
multi_xml (0.4.2)
|
56
53
|
polyglot (0.3.3)
|
57
54
|
rack (1.4.1)
|
58
55
|
rack-cache (1.2)
|
@@ -107,8 +104,8 @@ PLATFORMS
|
|
107
104
|
|
108
105
|
DEPENDENCIES
|
109
106
|
bundler (>= 1.0.0)
|
107
|
+
geoip
|
110
108
|
hashie (~> 1.2)
|
111
|
-
httparty
|
112
109
|
i18n (~> 0.6)
|
113
110
|
jeweler (>= 1.8.3)
|
114
111
|
rails (>= 3.1)
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# World Flags
|
2
2
|
|
3
|
-
This gem can be used with Rails 3
|
3
|
+
This engine/gem can be used with Rails 3+. WorldFlags includes css files for flags of the following pixel sizes:
|
4
|
+
* 16
|
5
|
+
* 32
|
6
|
+
* 64
|
7
|
+
|
8
|
+
The sprites contains all the main country flags in the world.
|
4
9
|
|
5
10
|
## Configuration
|
6
11
|
|
@@ -16,7 +21,7 @@ In you asset `application.css` manifest file:
|
|
16
21
|
*/
|
17
22
|
```
|
18
23
|
|
19
|
-
The `flags/basic` stylesheet sets up a basic css for use with borders around the
|
24
|
+
The `flags/basic` stylesheet sets up a basic css for use with borders around the flag images (to mark selected language). Use this css as inspiration and customize by overriding styles as needed.
|
20
25
|
|
21
26
|
There is also support for semi-transparent flags. This can be used to fade certain flags while having the selected flag (or hovered over flag) in full brightness.
|
22
27
|
|
@@ -28,9 +33,8 @@ Flags will be rendered in HTML as:
|
|
28
33
|
|
29
34
|
```html
|
30
35
|
<pre>
|
31
|
-
<ul class="f32">
|
32
|
-
|
33
|
-
<li class="flag gb" data-cc="gb" data-country="England">England</li>
|
36
|
+
<ul class="f32">
|
37
|
+
<li class="flag ar selected" data-cc="ar" data-country_name="Argentina" data-language_name="Spanish" data-locale="ar"> </li>
|
34
38
|
...
|
35
39
|
</ul>
|
36
40
|
</pre>
|
@@ -127,6 +131,37 @@ See the [wiki](https://github.com/kristianmandrup/world-flags/wiki/)
|
|
127
131
|
* [Configuration](https://github.com/kristianmandrup/world-flags/wiki/Configuration)
|
128
132
|
* [Handling flag selection](https://github.com/kristianmandrup/world-flags/wiki/Handling-flag-selection)
|
129
133
|
|
134
|
+
## Geo IP
|
135
|
+
|
136
|
+
Include the 'geoip' gem if you want to detect locale based on browser IP location.
|
137
|
+
|
138
|
+
[GeoIP country lite](http://www.maxmind.com/app/geolitecountry)
|
139
|
+
[GeoIP](http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz)
|
140
|
+
|
141
|
+
Extract and put latest `GeoIP.dat` file in `db/GeoIP.dat` of your Rails app. Alternatively set location via `WorldFlags.geo_ip_db_path = path`.
|
142
|
+
|
143
|
+
The _world-flags_ engine comes pre-packaged with a recent version of `GeoIP.dat` in the `db` folder of the engine itself.
|
144
|
+
|
145
|
+
### Localhosts filtering
|
146
|
+
|
147
|
+
Also set `WorldFlags.localhost_list` if you have localhosts other than the default `127.0.0.1`.
|
148
|
+
|
149
|
+
You can override the default ip passed to the `Geo module by overriding the `browser_ip` method in your controller. Here the default implementation is shown:
|
150
|
+
|
151
|
+
### Fine control of the IP used
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
def browser_ip
|
155
|
+
request.remote_ip
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
Code extract of the locale source logic for browser IP country code detection:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
when :ip
|
163
|
+
ip_country_code(browser_ip)
|
164
|
+
```
|
130
165
|
|
131
166
|
## TODO for version 1.0
|
132
167
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
data/db/GeoIP.dat
ADDED
Binary file
|
@@ -1,18 +1,24 @@
|
|
1
1
|
module WorldFlags
|
2
|
+
class GeoIPError < StandardError; end
|
3
|
+
|
2
4
|
module Helper
|
3
5
|
module Geo
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.ip_country_code ip = nil
|
7
|
+
ip ||= request.remote_ip
|
8
|
+
raise WorldFlags::GeoIPError, "IP address #{ip} is a localhost address" if local_ip?(ip)
|
9
|
+
|
10
|
+
@geoip ||= GeoIP.new WorldFlags.geo_ip_db_path
|
11
|
+
country = @geoip.country(ip)
|
12
|
+
return country[2] unless country.nil?
|
13
|
+
raise WorldFlags::GeoIPError, "No country code could be found for IP: #{ip}"
|
8
14
|
end
|
9
15
|
|
10
|
-
|
11
|
-
|
16
|
+
def self.local_ip? ip
|
17
|
+
WorldFlags.localhost_list.include?(ip)
|
12
18
|
end
|
13
19
|
|
14
|
-
def ip_country_code
|
15
|
-
WorldFlags::Helper::Geo.ip_country_code
|
20
|
+
def ip_country_code ip = nil
|
21
|
+
WorldFlags::Helper::Geo.ip_country_code ip
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -35,12 +35,16 @@ module WorldFlags
|
|
35
35
|
when :browser
|
36
36
|
browser_locale # http://www.metamodpro.com/browser-language-codes
|
37
37
|
when :ip
|
38
|
-
ip_country_code
|
38
|
+
ip_country_code(browser_ip)
|
39
39
|
when :default
|
40
40
|
I18n.default_locale
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def browser_ip
|
45
|
+
request.remote_ip
|
46
|
+
end
|
47
|
+
|
44
48
|
def locale_source_priority
|
45
49
|
WorldFlags.locale_source_priority
|
46
50
|
end
|
@@ -3,7 +3,15 @@ module WorldFlags
|
|
3
3
|
module Config
|
4
4
|
attr_accessor :auto_select, :raise_error
|
5
5
|
attr_accessor :default_code, :default_locale
|
6
|
-
attr_writer :locale_source_priority
|
6
|
+
attr_writer :locale_source_priority, :geo_ip_db_path, :localhost_list
|
7
|
+
|
8
|
+
def geo_ip_db_path
|
9
|
+
@geo_ip_db_path ||= "#{Rails.root}/db/GeoIP.dat"
|
10
|
+
end
|
11
|
+
|
12
|
+
def localhost_list
|
13
|
+
@localhost_list ||= ["127.0.0.1"]
|
14
|
+
end
|
7
15
|
|
8
16
|
def locale_source_priority
|
9
17
|
@locale_source_priority ||= default_locale_source_priority
|
data/spec/data/GeoIP.dat
ADDED
Binary file
|
data/world-flags.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "world-flags"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-16"
|
13
13
|
s.description = "Use world flag icons in your Rails app"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"config/countries/locale_countries.en.json",
|
30
30
|
"config/languages/locale_languages.en.json",
|
31
31
|
"config/locale_map/locale_to_country_code.json",
|
32
|
+
"db/GeoIP.dat",
|
32
33
|
"lib/generators/world_flags/init_generator.rb",
|
33
34
|
"lib/generators/world_flags/templates/world_flags.erb",
|
34
35
|
"lib/world-flags.rb",
|
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
|
|
54
55
|
"sandbox/languages_table.txt",
|
55
56
|
"sandbox/official_languages.html",
|
56
57
|
"sandbox/official_languages.txt",
|
58
|
+
"spec/data/GeoIP.dat",
|
57
59
|
"spec/spec_helper.rb",
|
58
60
|
"spec/world_flags/country_spec.rb",
|
59
61
|
"spec/world_flags/helper/locale_helper_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: world-flags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- config/countries/locale_countries.en.json
|
144
144
|
- config/languages/locale_languages.en.json
|
145
145
|
- config/locale_map/locale_to_country_code.json
|
146
|
+
- db/GeoIP.dat
|
146
147
|
- lib/generators/world_flags/init_generator.rb
|
147
148
|
- lib/generators/world_flags/templates/world_flags.erb
|
148
149
|
- lib/world-flags.rb
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- sandbox/languages_table.txt
|
169
170
|
- sandbox/official_languages.html
|
170
171
|
- sandbox/official_languages.txt
|
172
|
+
- spec/data/GeoIP.dat
|
171
173
|
- spec/spec_helper.rb
|
172
174
|
- spec/world_flags/country_spec.rb
|
173
175
|
- spec/world_flags/helper/locale_helper_spec.rb
|
@@ -211,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
213
|
version: '0'
|
212
214
|
segments:
|
213
215
|
- 0
|
214
|
-
hash: -
|
216
|
+
hash: -3422486010185457987
|
215
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
218
|
none: false
|
217
219
|
requirements:
|