diff --git a/CHANGELOG b/CHANGELOG index 54b7bf3..1c2c76d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +V0.2.2 +======== +* Country Name Locales + V.0.1.0 ======== * Helper method in order to get country info. diff --git a/README.md b/README.md index b12afde..85f2f7a 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,29 @@ Assuming that your User model store country cod.

Country Apha3s: <%= country(:num => @user.country_num)[3] %>

``` +### Locales + +By default all county names are in english, but you can change this behavior by include country names in +your locale file under `countries:` scope + +```yml +es: + countries: + AC: "Isla de la Ascensión" + AD: "Andorra" + AE: "Emiratos Árabes Unidos" + AF: "Afganistán" + AG: "Antigua y Barbuda" + AI: "Anguila" + AL: "Albania" + AM: "Armenia" +``` + +Please look at [@onomojo](https://github.com/onomojo) [repo](https://github.com/onomojo/i18n-country-translations/tree/master/rails/locale) for all translations + + + + ## Contributing 1. Fork it diff --git a/lib/country_definitions.rb b/lib/country_definitions.rb index e5c63be..aeca5e2 100644 --- a/lib/country_definitions.rb +++ b/lib/country_definitions.rb @@ -181,7 +181,7 @@ 'Portugal', 'Puerto Rico', 'Qatar', - 'Réunion', + 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', diff --git a/lib/rails_country_select.rb b/lib/rails_country_select.rb index 48969b2..6cb9e03 100644 --- a/lib/rails_country_select.rb +++ b/lib/rails_country_select.rb @@ -12,12 +12,12 @@ def country_select(object, method, options = {}, html_options = {}) options[:values] = :nums unless options.has_key?(:values) potential = { - :names => COUNTRY_NAMES, + :names => translate_countries, :nums => COUNTRY_NUMS, :alpha2s => COUNTRY_ALPHA2S, :alpha3s => COUNTRY_ALPHA3S } - + select_options = potential[options[:keys]].zip(potential[options[:values]]) InstanceTag.new(object, method, self, options.delete(:object)).to_select_tag(select_options, options, html_options) end @@ -32,13 +32,20 @@ def country_select(method, options = {}, html_options = {}) # get country info given some params def country(options = {:name => "", :num =>"", :alpha2s => "", :alpha3s => ""}) result = [] - COUNTRY_NUMS.zip(COUNTRY_NAMES, COUNTRY_ALPHA2S, COUNTRY_ALPHA3S).each do |country| - if options[:nums].to_i.eql?(country[0]) || options[:name].eql?(country[1]) || options[:alpha2s].eql?(country[2]) || options[:alpha3s].eql?(country[3]) - result = country + COUNTRY_NUMS.zip(translate_countries, COUNTRY_ALPHA2S, COUNTRY_ALPHA3S).each do |country| + if options[:num].to_i.eql?(country[0]) || options[:name].eql?(country[1]) || options[:alpha2s].eql?(country[2]) || options[:alpha3s].eql?(country[3]) + result = country end end result end + + private + def translate_countries + COUNTRY_ALPHA2S.zip(COUNTRY_NAMES).map do |code, name| + I18n.t(code, :scope => :countries, :default => name) + end + end end end end diff --git a/rails_country_select.gemspec b/rails_country_select.gemspec index fa7abea..e1f5d4e 100644 --- a/rails_country_select.gemspec +++ b/rails_country_select.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.email = ["rderoldan1@gmail.com"] spec.description = %q{Select tag for countries in rails form, based in LukeCarrier rails 2 plugin } spec.summary = %q{Select tag for countries in rails form} - spec.homepage = "" + spec.homepage = "https://github.com/rderoldan1/rails_country_select" spec.license = "MIT" spec.files = `git ls-files`.split($/)