Skip to content
Browse files

FIX that countries beginning with accented characters (Ägyptien, Špan…

…ělsko, etc) are listed in correct order, not at the end of the list
  • Loading branch information...
1 parent c96ea30 commit ca5ccd1821a5059bb69afe1ad8ba5b03710f34e5 @karmi committed Sep 30, 2009
Showing with 7 additions and 1 deletion.
  1. +2 −1 lib/localized_country_select.rb
  2. +5 −0 test/localized_country_select_test.rb
View
3 lib/localized_country_select.rb
@@ -23,7 +23,8 @@ class << self
# Returns array with codes and localized country names (according to <tt>I18n.locale</tt>)
# for <tt><option></tt> tags
def localized_countries_array
- I18n.translate(:countries).map { |key, value| [value, key.to_s.upcase] }.sort
+ I18n.translate(:countries).map { |key, value| [value, key.to_s.upcase] }.
+ sort_by { |country| country.first.parameterize }
end
# Return array with codes and localized country names for array of country codes passed as argument
# == Example
View
5 test/localized_country_select_test.rb
@@ -95,6 +95,11 @@ def test_priority_countries_allows_passing_upcase_or_lowercase
assert_equal [ ['United States', 'US'], ['Canada', 'CA'] ], LocalizedCountrySelect::priority_countries_array([:us, :ca])
end
+ def test_should_list_countries_with_accented_names_in_correct_order
+ I18n.locale = 'cz'
+ assert_match Regexp.new(Regexp.escape(%Q{<option value="BI">Burundi</option>\n<option value="TD">Čad</option>})), localized_country_select(:user, :country)
+ end
+
private
def setup

1 comment on commit ca5ccd1

@henrik
henrik commented on ca5ccd1 Aug 18, 2011

Does not give correct order in Swedish where Å, Ä and Ö are distinct characters that should sort after Z (as sort does).

There is no simple general solution since e.g. German sorts AÄB while Swedish sorts ZÄ.

Please sign in to comment.
Something went wrong with that request. Please try again.