rails_country_select 0.2.1 → 0.2.2

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/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ V0.2.2
2
+ ========
3
+ * Country Name Locales
4
+
1
5
  V.0.1.0
2
6
  ========
3
7
  * Helper method in order to get country info.
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
- # RailsCountrySelect
2
- This project is based on Rails 2 plugin created by LukeCarrier [rails-country-select](https://github.com/rderoldan1/rails-country-select/blob/master/lib/country_definitions.rb)
1
+ # RailsCountrySelect [![Gem Version](https://badge.fury.io/rb/rails_country_select.png)](http://badge.fury.io/rb/rails_country_select) [![Code Climate](https://codeclimate.com/github/rderoldan1/rails_country_select.png)](https://codeclimate.com/github/rderoldan1/rails_country_select)
3
2
 
4
- Select tag in order to choose a country in your forms, provides 4 options.
3
+ Rails 3 gem for Select tag in order to choose a country in your forms, provides 4 options.
4
+
5
+ *This project is based on Rails 2 plugin created by LukeCarrier [rails-country-select](https://github.com/rderoldan1/rails-country-select/blob/master/lib/country_definitions.rb)*
5
6
 
6
7
  1. Country Name.
7
8
  2. Cod
@@ -99,14 +100,39 @@ country(:alpha3s => "USA", :alpha2s => "US", :num => 840, :name => "United State
99
100
  [840, "United States", "US", "USA"]
100
101
  ```
101
102
 
103
+ #### Usage in views
102
104
 
103
- ```html
105
+ Assuming that your User model store country cod.
106
+ ```rails
104
107
  <p>Country Cod: <%= country(:num => @user.country_num)[0] %><p>
105
108
  <p>Country Name: <%= country(:num => @user.country_num)[1] %><p>
106
109
  <p>Country Apha2s: <%= country(:num => @user.country_num)[2] %><p>
107
110
  <p>Country Apha3s: <%= country(:num => @user.country_num)[3] %><p>
108
111
  ```
109
112
 
113
+ ### Locales
114
+
115
+ By default all county names are in english, but you can change this behavior by include country names in
116
+ your locale file under `countries:` scope
117
+
118
+ ```yml
119
+ es:
120
+ countries:
121
+ AC: "Isla de la Ascensión"
122
+ AD: "Andorra"
123
+ AE: "Emiratos Árabes Unidos"
124
+ AF: "Afganistán"
125
+ AG: "Antigua y Barbuda"
126
+ AI: "Anguila"
127
+ AL: "Albania"
128
+ AM: "Armenia"
129
+ ```
130
+
131
+ Please look at [@onomojo](https://github.com/onomojo) [repo](https://github.com/onomojo/i18n-country-translations/tree/master/rails/locale) for all translations
132
+
133
+
134
+
135
+
110
136
  ## Contributing
111
137
 
112
138
  1. Fork it
@@ -181,7 +181,7 @@ COUNTRY_NAMES = [
181
181
  'Portugal',
182
182
  'Puerto Rico',
183
183
  'Qatar',
184
- 'Réunion',
184
+ 'Reunion',
185
185
  'Romania',
186
186
  'Russian Federation',
187
187
  'Rwanda',
@@ -12,12 +12,12 @@ if defined?(Rails) && defined?(ActionView)
12
12
  options[:values] = :nums unless options.has_key?(:values)
13
13
 
14
14
  potential = {
15
- :names => COUNTRY_NAMES,
15
+ :names => translate_countries,
16
16
  :nums => COUNTRY_NUMS,
17
17
  :alpha2s => COUNTRY_ALPHA2S,
18
18
  :alpha3s => COUNTRY_ALPHA3S
19
19
  }
20
-
20
+
21
21
  select_options = potential[options[:keys]].zip(potential[options[:values]])
22
22
  InstanceTag.new(object, method, self, options.delete(:object)).to_select_tag(select_options, options, html_options)
23
23
  end
@@ -32,13 +32,20 @@ if defined?(Rails) && defined?(ActionView)
32
32
  # get country info given some params
33
33
  def country(options = {:name => "", :num =>"", :alpha2s => "", :alpha3s => ""})
34
34
  result = []
35
- COUNTRY_NUMS.zip(COUNTRY_NAMES, COUNTRY_ALPHA2S, COUNTRY_ALPHA3S).each do |country|
36
- if options[:nums].to_i.eql?(country[0]) || options[:name].eql?(country[1]) || options[:alpha2s].eql?(country[2]) || options[:alpha3s].eql?(country[3])
37
- result = country
35
+ COUNTRY_NUMS.zip(translate_countries, COUNTRY_ALPHA2S, COUNTRY_ALPHA3S).each do |country|
36
+ if options[:num].to_i.eql?(country[0]) || options[:name].eql?(country[1]) || options[:alpha2s].eql?(country[2]) || options[:alpha3s].eql?(country[3])
37
+ result = country
38
38
  end
39
39
  end
40
40
  result
41
41
  end
42
+
43
+ private
44
+ def translate_countries
45
+ COUNTRY_ALPHA2S.zip(COUNTRY_NAMES).map do |code, name|
46
+ I18n.t(code, :scope => :countries, :default => name)
47
+ end
48
+ end
42
49
  end
43
50
  end
44
51
  end
@@ -1,3 +1,3 @@
1
1
  module RailsCountrySelect
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["rderoldan1@gmail.com"]
11
11
  spec.description = %q{Select tag for countries in rails form, based in LukeCarrier rails 2 plugin }
12
12
  spec.summary = %q{Select tag for countries in rails form}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/rderoldan1/rails_country_select"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -61,7 +61,7 @@ files:
61
61
  - lib/rails_country_select.rb
62
62
  - lib/rails_country_select/version.rb
63
63
  - rails_country_select.gemspec
64
- homepage: ''
64
+ homepage: https://github.com/rderoldan1/rails_country_select
65
65
  licenses:
66
66
  - MIT
67
67
  post_install_message:
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: 4130862731204757103
79
+ hash: 685250971541583319
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: 4130862731204757103
88
+ hash: 685250971541583319
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.23