Skip to content

Commit

Permalink
made country names translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
chrkau committed Jul 17, 2013
1 parent be3618c commit c56d351
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/country_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
require 'country_select/version'
require 'country_select/countries'
require 'i18n'

module ActionView
module Helpers
Expand Down Expand Up @@ -76,7 +77,15 @@ def country_options_for_select(selected = nil, priority_countries = nil, use_iso
::CountrySelect::COUNTRIES_FOR_SELECT
end

return country_options + options_for_select(values, selected)
i18n_values = {}
if values.kind_of?(Hash)
values.each do |k, v|
i18n_values[I18n.t(k)] = v
end
else
i18n_values = values.map {|v| I18n.t(v)}.sort
end
return country_options + options_for_select(i18n_values, selected)
end

# All the countries included in the country_options output.
Expand Down
2 changes: 1 addition & 1 deletion lib/country_select/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ module CountrySelect
"ve" => "Venezuela, Bolivarian Republic of",
"vn" => "Viet Nam",
"vg" => "Virgin Islands, British",
"vi" => "Virgin Islands, U.S.",
"vi" => "Virgin Islands, US",
"wf" => "Wallis and Futuna",
"eh" => "Western Sahara",
"ye" => "Yemen",
Expand Down

3 comments on commit c56d351

@dgilperez
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for a pull request 👍

@chrkau
Copy link
Owner Author

@chrkau chrkau commented on c56d351 Aug 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be honest i wouldnt want anyone to use this code - its a really bad hack. i think there is a need for translateable country names though.

@dgilperez
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually a similar hack I did myself in my own fork ...

dgilperez/country_select@3a5e6fe

I also think this should be addressed. I opened an issue: countries#27

Please sign in to comment.