├── uninstall.rb
├── .gitignore
├── lib
├── localized_country_select
│ ├── version.rb
│ └── railtie.rb
├── localized_country_select.rb
└── tasks
│ └── localized_country_select_tasks.rake
├── install.rb
├── init.rb
├── Rakefile
├── MIT-LICENSE
├── localized_country_select.gemspec
├── README.rdoc
├── test
└── localized_country_select_test.rb
└── locale
├── cz.rb
└── en.rb
/uninstall.rb:
--------------------------------------------------------------------------------
1 | # Uninstall hook code here
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | */.DS_Store
3 | rdoc
4 | *.gem
5 |
--------------------------------------------------------------------------------
/lib/localized_country_select/version.rb:
--------------------------------------------------------------------------------
1 | module LocalizedCountrySelect
2 | VERSION = '0.10.2'
3 | end
4 |
--------------------------------------------------------------------------------
/install.rb:
--------------------------------------------------------------------------------
1 | # Show the README text file
2 | puts "\n\n"
3 | puts IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
4 | puts "\n"
--------------------------------------------------------------------------------
/init.rb:
--------------------------------------------------------------------------------
1 | # Require the plugin code
2 | require 'localized_country_select'
3 |
4 | # Load locales for countries from +locale+ directory into Rails
5 | I18n.load_path += Dir[ File.join(File.dirname(__FILE__), 'locale', '*.{rb,yml}') ]
--------------------------------------------------------------------------------
/lib/localized_country_select/railtie.rb:
--------------------------------------------------------------------------------
1 | require 'localized_country_select'
2 |
3 | module LocalizedCountrySelect
4 | if defined? Rails::Railtie
5 | require 'rails'
6 | class Railtie < Rails::Railtie
7 | rake_tasks do
8 | load "tasks/localized_country_select_tasks.rake"
9 | end
10 | end
11 | end
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rake'
2 | require 'rake/testtask'
3 | require 'rake/task'
4 |
5 | load File.join(File.dirname(__FILE__), 'lib', 'tasks', 'localized_country_select_tasks.rake')
6 |
7 | desc 'Default: run unit tests.'
8 | task :default => :test
9 |
10 | desc 'Test the localized_country_select plugin.'
11 | Rake::TestTask.new(:test) do |t|
12 | t.libs << 'lib'
13 | t.pattern = 'test/**/*_test.rb'
14 | t.verbose = true
15 | end
16 |
17 | #desc 'Generate documentation for the localized_country_select plugin.'
18 | #Rake::Task.new(:rdoc) do |rdoc|
19 | #rdoc.rdoc_dir = 'rdoc'
20 | #rdoc.title = 'LocalizedCountrySelect'
21 | #rdoc.options << '--line-numbers' << '--inline-source'
22 | #rdoc.rdoc_files.include('README.rdoc')
23 | #rdoc.rdoc_files.include('lib/**/*.rb')
24 | #end
25 |
--------------------------------------------------------------------------------
/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2008 [name of plugin creator]
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/localized_country_select.gemspec:
--------------------------------------------------------------------------------
1 | # -*- encoding: utf-8 -*-
2 | require File.expand_path('../lib/localized_country_select/version', __FILE__)
3 |
4 | Gem::Specification.new do |gem|
5 | gem.authors = ['karmi', 'mlitwiniuk', 'LIM SAS', 'Damien MATHIEU', 'Julien SANCHEZ', 'Herv\303\251 GAUCHER', 'RainerBlessing', 'bbenno']
6 | gem.email = [nil, 'maciej@litwiniuk.net', nil, nil, nil, nil, nil, 'bbenno@digitize-it.de']
7 | gem.description = %q( Localized "country_select" helper with Rake task for downloading locales from Unicode.org's CLDR )
8 | gem.summary = %q( Localized "country_select" helper with Rake task for downloading locales from Unicode.org's CLDR )
9 | gem.homepage = 'https://github.com/mlitwiniuk/localized_country_select'
10 | gem.license = 'MIT'
11 |
12 | gem.files = `git ls-files`.split("\n") - %w(localized_country_select.gemspec Gemfile init.rb)
13 | gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
14 | gem.test_files = gem.files.grep(/^(test|spec|features)\//)
15 | gem.name = 'localized_country_select'
16 | gem.require_paths = ['lib']
17 | gem.version = LocalizedCountrySelect::VERSION
18 | gem.add_dependency 'actionpack', '>= 5.0'
19 | end
20 |
--------------------------------------------------------------------------------
/README.rdoc:
--------------------------------------------------------------------------------
1 | = LocalizedCountrySelect
2 |
3 | Rails plugin to provide support for localized menu with country names and for
4 | storing country information as country _code_ (eg. 'es'), not _name_ (eg. 'Spain'), in the database.
5 |
6 | Uses the Rails internationalization framework (I18n, http://rails-i18n.org) for translating the names of countries.
7 | Requires Rails 2.2 (released November 21st, 2008) or later versions.
8 | Country names are loaded from hashes in plugin directory, according to I18n.locale value.
9 |
10 | You can easily translate country codes in your application like this:
11 |
12 | <%= I18n.t @user.country, :scope => 'countries' %>
13 |
14 | Comes with a Rake task rails import:country_select LOCALE=de for importing country names
15 | from Unicode.org's CLDR repository (http://www.unicode.org/cldr/data/charts/summary/root.html)
16 | Don't forget to restart the application when you add new locale.
17 |
18 | ActionView helper code is adapted from Rails' default +country_select+ plugin (previously in core).
19 | See http://github.com/rails/country_select/tree/master/lib/country_select.rb
20 |
21 | == Rails 5 / Rails 6
22 |
23 | In your Gemfile add:
24 |
25 | gem 'localized_country_select', '>= 0.10.2'
26 |
27 | == Rails 3 / Rails 4
28 |
29 | In your Gemfile add:
30 |
31 | gem 'localized_country_select', '= 0.9.11'
32 |
33 | == Rails 2.3
34 |
35 | No longer supported, but you can still use old version of gem.
36 | In environment.rb add
37 |
38 | config.gem 'localized_country_select', :version => '0.0.1'
39 |
40 | == Example
41 |
42 | Show full country names:
43 |
44 | <%= localized_country_select(:user, :country, [], {include_blank: 'Please choose...'}) %>
45 |
46 | will become:
47 |
48 |
55 |
56 |
57 | Show only country codes:
58 |
59 | <%= localized_country_select(:user, :country, [], {include_blank: 'Please choose...', description: :abbreviated}) %>
60 |
61 | will become:
62 |
63 |
70 |
71 |
72 | for the en locale.
73 |
74 |
75 | You can exclude countries by code using the exclude option (a single code or an array of country codes):
76 |
77 | localized_country_select(:user, :country, [], {exclude: [:ZZ, :US]})
78 |
79 |
80 | == Formtastic and SimpleForm
81 |
82 | Gem supports (via alias_method) both formtastic and simple_form :country input
83 |
84 | == Other resources
85 |
86 | * http://github.com/rails/country_select (Default Rails plugin)
87 | * http://github.com/russ/country_code_select (Stores country code, not name)
88 |
89 |
90 | Copyright (c) 2008 Karel Minarik (www.karmi.cz), released under the MIT license
91 |
--------------------------------------------------------------------------------
/test/localized_country_select_test.rb:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 | require 'test/unit'
3 |
4 | require 'rubygems'
5 | require 'active_support'
6 | require 'action_dispatch'
7 | require 'action_dispatch/testing/test_process'
8 | require 'action_view'
9 | require 'action_view/helpers'
10 | require 'action_view/helpers/tag_helper'
11 | require 'i18n'
12 |
13 | begin
14 | require 'redgreen'
15 | rescue LoadError
16 | puts "[!] Install redgreen gem for better test output ($ sudo gem install redgreen)"
17 | end unless ENV["TM_FILEPATH"]
18 |
19 | require 'localized_country_select'
20 |
21 | class LocalizedCountrySelectTest < Test::Unit::TestCase
22 |
23 | include ActionView::Helpers::TagHelper
24 | include ActionView::Helpers::FormOptionsHelper
25 | include ActionView::Helpers::FormTagHelper
26 |
27 | def test_action_view_should_include_helper_for_object
28 | assert ActionView::Helpers::FormBuilder.instance_methods.member?(:localized_country_select)
29 | assert ActionView::Helpers::FormOptionsHelper.instance_methods.include?(:localized_country_select)
30 | end
31 |
32 | def test_action_view_should_include_helper_tag
33 | assert ActionView::Helpers::FormOptionsHelper.instance_methods.include?(:localized_country_select_tag)
34 | end
35 |
36 | def test_should_return_select_tag_with_proper_name_for_object
37 | assert localized_country_select(:user, :country) =~
38 | Regexp.new(Regexp.escape('