brainsome_localized_country_select 0.9.10
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.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +13 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +84 -0
- data/Rakefile +24 -0
- data/install.rb +4 -0
- data/lib/localized_country_select/railtie.rb +13 -0
- data/lib/localized_country_select/version.rb +3 -0
- data/lib/localized_country_select.rb +134 -0
- data/lib/tasks/localized_country_select_tasks.rake +222 -0
- data/locale/cz.rb +259 -0
- data/locale/en.rb +275 -0
- data/test/localized_country_select_test.rb +132 -0
- data/uninstall.rb +1 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa7f88f79da92af82183bb6c113c73087b6407d4
|
4
|
+
data.tar.gz: 4e42189f21f557902411ef36feb6e2eec5400196
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70a864ff607803432057e72772f8645b9e988f44af3fccb4a4e25b83155689272bb68c9c3e8926c5f32e6b1ddf5af7373bbe78507bcab510045147e2e77534fa
|
7
|
+
data.tar.gz: d44e34c3c28722686974e218f93b4157c7871467ec9e5b202a962f56df8a1efd18a09d50307945fd7182254ef2f645c377c91c024b8ffba3c7ce9e07e00fd2d7
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
.DS_Store
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
.ruby-gemset
|
20
|
+
.ruby-version
|
21
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= LocalizedCountrySelect
|
2
|
+
|
3
|
+
Rails plugin to provide support for localized <tt><select></tt> 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 <tt>I18n.locale</tt> 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 <tt>rake import:country_select LOCALE=de</tt> 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 3 / Rails 4
|
22
|
+
|
23
|
+
In your Gemfile add:
|
24
|
+
|
25
|
+
gem 'localized_country_select', '>= 0.9.9'
|
26
|
+
|
27
|
+
== Rails 2.3
|
28
|
+
|
29
|
+
No longer supported, but you can still use old version of gem.
|
30
|
+
In environment.rb add
|
31
|
+
|
32
|
+
config.gem 'localized_country_select', :version => '0.0.1'
|
33
|
+
|
34
|
+
== Example
|
35
|
+
|
36
|
+
Show full country names:
|
37
|
+
|
38
|
+
<%= localized_country_select(:user, :country, [], {:include_blank => 'Please choose...'}) %>
|
39
|
+
|
40
|
+
will become:
|
41
|
+
|
42
|
+
<select name="user[country]" id="user_country">
|
43
|
+
<option value="">Please choose...</option>
|
44
|
+
<option disabled="disabled" value="">-------------</option>
|
45
|
+
<option value="AF">Afghanistan</option>
|
46
|
+
...
|
47
|
+
<option value="ZW">Zimbabwe</option>
|
48
|
+
</select>
|
49
|
+
|
50
|
+
|
51
|
+
Show only country codes:
|
52
|
+
|
53
|
+
<%= localized_country_select(:user, :country, [], {:include_blank => 'Please choose...', :description => :abbreviated}) %>
|
54
|
+
|
55
|
+
will become:
|
56
|
+
|
57
|
+
<select name="user[country]" id="user_country">
|
58
|
+
<option value="">Please choose...</option>
|
59
|
+
<option disabled="disabled" value="">-------------</option>
|
60
|
+
<option value="AF">AF</option>
|
61
|
+
...
|
62
|
+
<option value="ZW">ZW</option>
|
63
|
+
</select>
|
64
|
+
|
65
|
+
|
66
|
+
for the <tt>en</tt> locale.
|
67
|
+
|
68
|
+
|
69
|
+
You can exclude countries by code using the exclude option (a single code or an array of country codes):
|
70
|
+
|
71
|
+
localized_country_select(:user, :country, [], {:exclude => [:ZZ, :US]})
|
72
|
+
|
73
|
+
|
74
|
+
== Formtastic and SimpleForm
|
75
|
+
|
76
|
+
Gem supports (via alias_method) both formtastic and simple_form :country input
|
77
|
+
|
78
|
+
== Other resources
|
79
|
+
|
80
|
+
* http://github.com/rails/country_select (Default Rails plugin)
|
81
|
+
* http://github.com/russ/country_code_select (Stores country code, not name)
|
82
|
+
|
83
|
+
|
84
|
+
Copyright (c) 2008 Karel Minarik (www.karmi.cz), released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
data/install.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# = LocalizedCountrySelect
|
2
|
+
#
|
3
|
+
# View helper for displaying select list with countries:
|
4
|
+
#
|
5
|
+
# localized_country_select(:user, :country)
|
6
|
+
#
|
7
|
+
# Works just like the default Rails' +country_select+ plugin, but stores countries as
|
8
|
+
# country *codes*, not *names*, in the database.
|
9
|
+
#
|
10
|
+
# You can easily translate country codes in your application like this:
|
11
|
+
# <%= I18n.t @user.country, :scope => 'countries' %>
|
12
|
+
#
|
13
|
+
# Uses the Rails internationalization framework (I18n) for translating the names of countries.
|
14
|
+
#
|
15
|
+
# Use Rake task <tt>rake import:country_select 'de'</tt> for importing country names
|
16
|
+
# from Unicode.org's CLDR repository (http://www.unicode.org/cldr/data/charts/summary/root.html)
|
17
|
+
#
|
18
|
+
# Code 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
|
+
|
22
|
+
module LocalizedCountrySelect
|
23
|
+
class << self
|
24
|
+
# Returns array with codes and localized country names (according to <tt>I18n.locale</tt>)
|
25
|
+
# for <tt><option></tt> tags
|
26
|
+
def localized_countries_array(options={})
|
27
|
+
exclude = Array(options[:exclude]).map {|code| code.to_s.upcase }
|
28
|
+
locale = options.delete(:locale) || I18n.locale
|
29
|
+
|
30
|
+
if(options[:description]==:abbreviated)
|
31
|
+
I18n.translate(:countries, locale: locale).map { |key, value| [key.to_s.upcase] if !exclude.include?(key.to_s.upcase) }
|
32
|
+
else
|
33
|
+
I18n.translate(:countries, locale: locale).map { |key, value| [value, key.to_s.upcase] if !exclude.include?(key.to_s.upcase) }
|
34
|
+
end.compact.sort_by { |country| country.first.parameterize }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return array with codes and localized country names for array of country codes passed as argument
|
38
|
+
# == Example
|
39
|
+
# priority_countries_array([:TW, :CN])
|
40
|
+
# # => [ ['Taiwan', 'TW'], ['China', 'CN'] ]
|
41
|
+
def priority_countries_array(country_codes=[],options={})
|
42
|
+
if(options[:description]==:abbreviated)
|
43
|
+
country_codes.map { |code| [code.to_s.upcase] }
|
44
|
+
else
|
45
|
+
countries = I18n.translate(:countries)
|
46
|
+
country_codes.map { |code| [countries[code.to_s.upcase.to_sym], code.to_s.upcase] }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module ActionView
|
53
|
+
module Helpers
|
54
|
+
|
55
|
+
module FormOptionsHelper
|
56
|
+
# Return select and option tags for the given object and method, using +localized_country_options_for_select+
|
57
|
+
# to generate the list of option tags. Uses <b>country code</b>, not name as option +value+.
|
58
|
+
# Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
|
59
|
+
# TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
|
60
|
+
def localized_country_select(object, method, priority_countries = nil, options = {}, html_options = {})
|
61
|
+
tag = if defined?(ActionView::Helpers::InstanceTag) &&
|
62
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
63
|
+
|
64
|
+
InstanceTag.new(object, method, self, options.delete(:object))
|
65
|
+
else
|
66
|
+
CountrySelect.new(object, method, self, options)
|
67
|
+
end
|
68
|
+
|
69
|
+
tag.to_localized_country_select_tag(priority_countries, options, html_options)
|
70
|
+
end
|
71
|
+
alias_method :country_select, :localized_country_select
|
72
|
+
|
73
|
+
# Return "named" select and option tags according to given arguments.
|
74
|
+
# Use +selected_value+ for setting initial value
|
75
|
+
# It behaves likes older object-binded brother +localized_country_select+ otherwise
|
76
|
+
# TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
|
77
|
+
def localized_country_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {})
|
78
|
+
select_tag name.to_sym, localized_country_options_for_select(selected_value, priority_countries).html_safe, html_options.stringify_keys
|
79
|
+
end
|
80
|
+
alias_method :country_select_tag, :localized_country_select_tag
|
81
|
+
|
82
|
+
# Returns a string of option tags for countries according to locale. Supply the country code in upper-case ('US', 'DE')
|
83
|
+
# as +selected+ to have it marked as the selected option tag.
|
84
|
+
# Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
|
85
|
+
def localized_country_options_for_select(selected = nil, priority_countries = nil, options={})
|
86
|
+
country_options = "".html_safe
|
87
|
+
if priority_countries
|
88
|
+
country_options += options_for_select(LocalizedCountrySelect::priority_countries_array(priority_countries, options), selected)
|
89
|
+
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
|
90
|
+
return country_options + options_for_select(LocalizedCountrySelect::localized_countries_array(options) - LocalizedCountrySelect::priority_countries_array(priority_countries, options), selected)
|
91
|
+
else
|
92
|
+
return country_options + options_for_select(LocalizedCountrySelect::localized_countries_array(options), selected)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
alias_method :country_options_for_select, :localized_country_options_for_select
|
96
|
+
end
|
97
|
+
|
98
|
+
module ToCountrySelectTag
|
99
|
+
def to_localized_country_select_tag(priority_countries, options, html_options)
|
100
|
+
html_options = html_options.stringify_keys
|
101
|
+
add_default_name_and_id(html_options)
|
102
|
+
value = value(object)
|
103
|
+
content_tag("select",
|
104
|
+
add_options(
|
105
|
+
localized_country_options_for_select(value, priority_countries, options).html_safe,
|
106
|
+
options, value
|
107
|
+
), html_options
|
108
|
+
)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if defined?(ActionView::Helpers::InstanceTag) && ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
113
|
+
class InstanceTag
|
114
|
+
include ToCountrySelectTag
|
115
|
+
end
|
116
|
+
else
|
117
|
+
class CountrySelect < Tags::Base
|
118
|
+
include ToCountrySelectTag
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class FormBuilder
|
123
|
+
def localized_country_select(method, priority_countries = nil, options = {}, html_options = {})
|
124
|
+
@template.localized_country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
|
125
|
+
end
|
126
|
+
alias_method :country_select, :localized_country_select
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
if defined?(Rails)
|
133
|
+
require "localized_country_select/railtie"
|
134
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
# Rake task for importing country names from Unicode.org's CLDR repository
|
6
|
+
# (http://www.unicode.org/cldr/data/charts/summary/root.html).
|
7
|
+
#
|
8
|
+
# It parses a HTML file from Unicode.org for given locale and saves the
|
9
|
+
# Rails' I18n hash in the plugin +locale+ directory
|
10
|
+
#
|
11
|
+
# Don't forget to restart the application when you add new locale to load it into Rails!
|
12
|
+
#
|
13
|
+
# == Parameters
|
14
|
+
# LOCALE (required): Sets the locale to use. Output file name will include this.
|
15
|
+
# FORMAT (optional): Output format, either 'rb' or 'yml'. Defaults to 'rb' if not specified.
|
16
|
+
# WEB_LOCALE (optional): Forces a locale code to use when querying the Unicode.org CLDR archive.
|
17
|
+
# PARSER (optional): Forces parser to use. Available are nokogiri, hpricot and libxml.
|
18
|
+
#
|
19
|
+
# == Examples
|
20
|
+
# rake import:country_select LOCALE=de
|
21
|
+
# rake import:country_select LOCALE=pt-BR WEB_LOCALE=pt FORMAT=yml
|
22
|
+
#
|
23
|
+
# The code is deliberately procedural and simple, so it's easily
|
24
|
+
# understandable by beginners as an introduction to Rake tasks power.
|
25
|
+
# See https://github.com/svenfuchs/ruby-cldr for much more robust solution
|
26
|
+
|
27
|
+
namespace :import do
|
28
|
+
|
29
|
+
desc "Import country codes and names for various languages from the Unicode.org CLDR archive."
|
30
|
+
task :country_select do
|
31
|
+
# TODO : Implement locale import chooser from CLDR root via Highline
|
32
|
+
|
33
|
+
# Setup variables
|
34
|
+
locale = ENV['LOCALE']
|
35
|
+
unless locale
|
36
|
+
puts "\n[!] Usage: rake import:country_select LOCALE=de\n\n"
|
37
|
+
exit 0
|
38
|
+
end
|
39
|
+
|
40
|
+
# convert locale code to Unicode.org CLDR acceptable code
|
41
|
+
web_locale = if ENV['WEB_LOCALE'] then ENV['WEB_LOCALE']
|
42
|
+
elsif %w(zht zhtw).include?(locale.downcase.gsub(/[-_]/,'')) then 'zh_Hant'
|
43
|
+
elsif %w(zhs zhcn).include?(locale.downcase.gsub(/[-_]/,'')) then 'zh_Hans'
|
44
|
+
else locale.underscore.split('_')[0] end
|
45
|
+
|
46
|
+
# ----- Get the CLDR HTML --------------------------------------------------
|
47
|
+
begin
|
48
|
+
puts "... getting the HTML file for locale '#{web_locale}'"
|
49
|
+
url = "http://www.unicode.org/cldr/data/charts/summary/#{web_locale}.html"
|
50
|
+
html = open(url).read
|
51
|
+
rescue => e
|
52
|
+
puts "[!] Invalid locale name '#{web_locale}'! Not found in CLDR (#{e})"
|
53
|
+
exit 0
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
set_parser(ENV['PARSER']) if ENV['PARSER']
|
58
|
+
puts "... parsing the HTML file using #{parser.name.split("::").last}"
|
59
|
+
countries = parser.parse(html).inject([]) { |arr, (code, attrs)| arr << attrs }
|
60
|
+
countries.sort_by! { |c| c[:code] }
|
61
|
+
puts "\n\n... imported #{countries.count} countries:"
|
62
|
+
puts countries.map { |c| "#{c[:code]}: #{c[:name]}" }.join(", ")
|
63
|
+
|
64
|
+
|
65
|
+
# ----- Prepare the output format ------------------------------------------
|
66
|
+
|
67
|
+
format = if ENV['FORMAT'].nil?||%(rb ruby).include?(ENV['FORMAT'].downcase) then :rb
|
68
|
+
elsif %(yml yaml).include?(ENV['FORMAT'].downcase) then :yml end
|
69
|
+
|
70
|
+
unless format
|
71
|
+
puts "\n[!] FORMAT must be either 'rb' or 'yml'\n\n"
|
72
|
+
exit 0
|
73
|
+
end
|
74
|
+
|
75
|
+
if format==:yml
|
76
|
+
output =<<HEAD
|
77
|
+
#{locale}:
|
78
|
+
countries:
|
79
|
+
HEAD
|
80
|
+
countries.each do |country|
|
81
|
+
output << " \"#{country[:code]}\": \"#{country[:name]}\"\n"
|
82
|
+
end
|
83
|
+
|
84
|
+
else # rb format
|
85
|
+
output = "#encoding: UTF-8\n"
|
86
|
+
output <<<<HEAD
|
87
|
+
{ :#{locale} => {
|
88
|
+
|
89
|
+
:countries => {
|
90
|
+
HEAD
|
91
|
+
countries.each do |country|
|
92
|
+
output << "\t\t\t:#{country[:code]} => \"#{country[:name]}\",\n"
|
93
|
+
end
|
94
|
+
output <<<<TAIL
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
}
|
99
|
+
TAIL
|
100
|
+
end
|
101
|
+
|
102
|
+
# ----- Write the parsed values into file ---------------------------------
|
103
|
+
puts "\n... writing the output"
|
104
|
+
filename = Rails.root.join('config', 'locales', "countries.#{locale}.#{format}")
|
105
|
+
if filename.exist?
|
106
|
+
filename = Pathname.new("#{filename.to_s}.NEW")
|
107
|
+
end
|
108
|
+
File.open(filename, 'w+') { |f| f << output }
|
109
|
+
puts "\n---\nWritten values for the '#{locale}' into file: #{filename}\n"
|
110
|
+
# ------------------------------------------------------------------------------
|
111
|
+
end
|
112
|
+
|
113
|
+
module LocalizedCountrySelectTasks
|
114
|
+
class Parser
|
115
|
+
attr_reader :html
|
116
|
+
|
117
|
+
def initialize(html)
|
118
|
+
@html = html
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.parse(html)
|
122
|
+
self.new(html).parse
|
123
|
+
end
|
124
|
+
|
125
|
+
def parse
|
126
|
+
raise NotImplementedError, "#parse method need to be implemented in child class!"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class NokogiriParser < Parser
|
131
|
+
def document
|
132
|
+
@document ||= Nokogiri::HTML(html)
|
133
|
+
end
|
134
|
+
|
135
|
+
def parse
|
136
|
+
document.search("//tr").inject({}) do |hash, row|
|
137
|
+
n = row.search("td[@class='n']")
|
138
|
+
g = row.search("td")
|
139
|
+
if n.inner_html =~ /NamesTerritories/ && g.count >= 6 && g[4].inner_html =~ /^[A-Z]{2}/
|
140
|
+
code = g[4].inner_text
|
141
|
+
code = code[-code.size, 2].to_sym
|
142
|
+
name = row.search("td[@class='v']:not([@title])").inner_text
|
143
|
+
|
144
|
+
hash[code] = {:code => code, :name => name.to_s}
|
145
|
+
end
|
146
|
+
hash
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class HpricotParser < NokogiriParser
|
152
|
+
def document
|
153
|
+
@document ||= Hpricot(html)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class LibXMLParser < Parser
|
158
|
+
def document
|
159
|
+
@document ||= LibXML::XML::HTMLParser.string(html, options: LibXML::XML::HTMLParser::Options::RECOVER).parse
|
160
|
+
end
|
161
|
+
|
162
|
+
def parse
|
163
|
+
document.find("//tr").inject({}) do |hash, row|
|
164
|
+
n = row.find("td[@class='n']")
|
165
|
+
g = row.find("td")
|
166
|
+
if n.map(&:content).join =~ /NamesTerritories/ && g.count >= 6 && g[4].inner_xml =~ /^[A-Z]{2}/
|
167
|
+
code = g[4].content
|
168
|
+
code = code[-code.size, 2].to_sym
|
169
|
+
name = row.find("td[@class='v' and not(@title)]").map(&:content).join
|
170
|
+
|
171
|
+
hash[code] ||= {:code => code, :name => name.to_s}
|
172
|
+
end
|
173
|
+
hash
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
REQUIREMENTS_MAP = [
|
179
|
+
['nokogiri', :Nokogiri],
|
180
|
+
['hpricot', :Hpricot],
|
181
|
+
['libxml', :LibXML]
|
182
|
+
]
|
183
|
+
|
184
|
+
def self.detect_parser
|
185
|
+
REQUIREMENTS_MAP.each do |library, klass|
|
186
|
+
return const_get(:"#{klass}Parser") if const_defined?(klass)
|
187
|
+
end
|
188
|
+
|
189
|
+
REQUIREMENTS_MAP.each do |library, klass|
|
190
|
+
begin
|
191
|
+
require library
|
192
|
+
return const_get(:"#{klass}Parser")
|
193
|
+
rescue LoadError
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
raise StandardError, "One of nokogiri, hpricot or libxml-ruby gem is required! Add \"gem 'nokogiri'\" to your Gemfile to resolve this issue."
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def parser
|
202
|
+
@parser ||= LocalizedCountrySelectTasks.detect_parser
|
203
|
+
end
|
204
|
+
|
205
|
+
def set_parser(arg)
|
206
|
+
@parser = begin
|
207
|
+
parser = nil
|
208
|
+
requirements = LocalizedCountrySelectTasks::REQUIREMENTS_MAP
|
209
|
+
found = requirements.detect { |library, _| library == arg }
|
210
|
+
raise ArgumentError, "Can't find parser for #{arg}! Supported parsers are: #{requirements.map(&:first).join(", ")}." unless found
|
211
|
+
library, klass = found
|
212
|
+
begin
|
213
|
+
require library
|
214
|
+
parser = LocalizedCountrySelectTasks.const_get(:"#{klass}Parser")
|
215
|
+
rescue LoadError
|
216
|
+
gem_name = library == 'libxml' ? 'libxml-ruby' : library
|
217
|
+
raise ArgumentError, "Can't find #{library} library! Add \"gem '#{gem_name}'\" to Gemfile."
|
218
|
+
end
|
219
|
+
parser
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
data/locale/cz.rb
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
{ :cz => {
|
2
|
+
|
3
|
+
:countries => {
|
4
|
+
:AD => "Andorra",
|
5
|
+
:AE => "Spojené arabské emiráty",
|
6
|
+
:AF => "Afghánistán",
|
7
|
+
:AG => "Antigua a Barbuda",
|
8
|
+
:AI => "Anguila",
|
9
|
+
:AL => "Albánie",
|
10
|
+
:AM => "Arménie",
|
11
|
+
:AN => "Nizozemské Antily",
|
12
|
+
:AO => "Angola",
|
13
|
+
:AQ => "Antarktida",
|
14
|
+
:AR => "Argentina",
|
15
|
+
:AS => "Americká Samoa",
|
16
|
+
:AT => "Rakousko",
|
17
|
+
:AU => "Austrálie",
|
18
|
+
:AW => "Aruba",
|
19
|
+
:AX => "Alandy",
|
20
|
+
:AZ => "Ázerbájdžán",
|
21
|
+
:BA => "Bosna a Hercegovina",
|
22
|
+
:BB => "Barbados",
|
23
|
+
:BD => "Bangladéš",
|
24
|
+
:BE => "Belgie",
|
25
|
+
:BF => "Burkina Faso",
|
26
|
+
:BG => "Bulharsko",
|
27
|
+
:BH => "Bahrajn",
|
28
|
+
:BI => "Burundi",
|
29
|
+
:BJ => "Benin",
|
30
|
+
:BL => "Svatý Bartolomějd",
|
31
|
+
:BM => "Bermudy",
|
32
|
+
:BN => "Brunej Darussalam",
|
33
|
+
:BO => "Bolívie",
|
34
|
+
:BR => "Brazílie",
|
35
|
+
:BS => "Bahamy",
|
36
|
+
:BT => "Bhútán",
|
37
|
+
:BV => "Ostrov Bouvet",
|
38
|
+
:BW => "Botswana",
|
39
|
+
:BY => "Bělorusko",
|
40
|
+
:BZ => "Belize",
|
41
|
+
:CA => "Kanada",
|
42
|
+
:CC => "Kokosové ostrovy",
|
43
|
+
:CD => "Demokratická republika Kongo",
|
44
|
+
:CF => "Středoafrická republika",
|
45
|
+
:CG => "Kongo",
|
46
|
+
:CH => "Švýcarsko",
|
47
|
+
:CI => "Pobřeží slonoviny",
|
48
|
+
:CK => "Cookovy ostrovy",
|
49
|
+
:CL => "Chile",
|
50
|
+
:CM => "Kamerun",
|
51
|
+
:CN => "Čína",
|
52
|
+
:CO => "Kolumbie",
|
53
|
+
:CR => "Kostarika",
|
54
|
+
:CS => "Srbsko a Černá HoraR014",
|
55
|
+
:CU => "Kuba",
|
56
|
+
:CV => "Kapverdy",
|
57
|
+
:CX => "Vánoční ostrovy",
|
58
|
+
:CY => "Kypr",
|
59
|
+
:CZ => "Česká republika",
|
60
|
+
:DE => "Německo",
|
61
|
+
:DJ => "Džibuti",
|
62
|
+
:DK => "Dánsko",
|
63
|
+
:DM => "Dominika",
|
64
|
+
:DO => "Dominikánská republika",
|
65
|
+
:DZ => "Alžírsko",
|
66
|
+
:EC => "Ekvádor",
|
67
|
+
:EE => "Estonsko",
|
68
|
+
:EG => "Egypt",
|
69
|
+
:EH => "Západní Sahara",
|
70
|
+
:ER => "Eritrea",
|
71
|
+
:ES => "Španělsko",
|
72
|
+
:ET => "Etiopie",
|
73
|
+
:FI => "Finsko",
|
74
|
+
:FJ => "Fidži",
|
75
|
+
:FK => "Falklandské ostrovy",
|
76
|
+
:FM => "Mikronézie",
|
77
|
+
:FO => "Faerské ostrovy",
|
78
|
+
:FR => "Francie",
|
79
|
+
:GA => "Gabon",
|
80
|
+
:GB => "Velká Británie",
|
81
|
+
:GD => "Grenada",
|
82
|
+
:GE => "Gruzie",
|
83
|
+
:GF => "Francouzská Guyana",
|
84
|
+
:GG => "Guernsey",
|
85
|
+
:GH => "Ghana",
|
86
|
+
:GI => "Gibraltar",
|
87
|
+
:GL => "Grónsko",
|
88
|
+
:GM => "Gambie",
|
89
|
+
:GN => "Guinea",
|
90
|
+
:GP => "Guadeloupe",
|
91
|
+
:GQ => "Rovníková Guinea",
|
92
|
+
:GR => "Řecko",
|
93
|
+
:GS => "Jižní Georgie a Jižní Sandwichovy ostrovy",
|
94
|
+
:GT => "Guatemala",
|
95
|
+
:GU => "Guam",
|
96
|
+
:GW => "Guinea-Bissau",
|
97
|
+
:GY => "Guyana",
|
98
|
+
:HK => "Hongkong, zvláštní administrativní oblast Číny",
|
99
|
+
:HK => "Hongkong",
|
100
|
+
:HM => "Ostrovy Heard a McDonald",
|
101
|
+
:HN => "Honduras",
|
102
|
+
:HR => "Chorvatsko",
|
103
|
+
:HT => "Haiti",
|
104
|
+
:HU => "Maďarsko",
|
105
|
+
:ID => "Indonésie",
|
106
|
+
:IE => "Irsko",
|
107
|
+
:IL => "Izrael",
|
108
|
+
:IM => "Ostrov Man",
|
109
|
+
:IN => "Indie",
|
110
|
+
:IO => "Britské území v Indickém oceánu",
|
111
|
+
:IQ => "Irák",
|
112
|
+
:IR => "Írán",
|
113
|
+
:IS => "Island",
|
114
|
+
:IT => "Itálie",
|
115
|
+
:JE => "Jersey",
|
116
|
+
:JM => "Jamajka",
|
117
|
+
:JO => "Jordánsko",
|
118
|
+
:JP => "Japonsko",
|
119
|
+
:KE => "Keňa",
|
120
|
+
:KG => "Kyrgyzstán",
|
121
|
+
:KH => "Kambodža",
|
122
|
+
:KI => "Kiribati",
|
123
|
+
:KM => "Komory",
|
124
|
+
:KN => "Svatý Kitts a Nevis",
|
125
|
+
:KP => "Severní Korea",
|
126
|
+
:KR => "Jižní Korea",
|
127
|
+
:KW => "Kuvajt",
|
128
|
+
:KY => "Kajmanské ostrovy",
|
129
|
+
:KZ => "Kazachstán",
|
130
|
+
:LA => "Lidově demokratická republika Laos",
|
131
|
+
:LB => "Libanon",
|
132
|
+
:LC => "Svatá Lucie",
|
133
|
+
:LI => "Lichtenštejnsko",
|
134
|
+
:LK => "Srí Lanka",
|
135
|
+
:LR => "Libérie",
|
136
|
+
:LS => "Lesotho",
|
137
|
+
:LT => "Litva",
|
138
|
+
:LU => "Lucembursko",
|
139
|
+
:LV => "Lotyšsko",
|
140
|
+
:LY => "Libye",
|
141
|
+
:MA => "Maroko",
|
142
|
+
:MC => "Monako",
|
143
|
+
:MD => "Moldavsko, republika",
|
144
|
+
:ME => "Černá Hora",
|
145
|
+
:MF => "Svatý Martin; [draft=contributed]",
|
146
|
+
:MG => "Madagaskar",
|
147
|
+
:MH => "Marshallovy ostrovy",
|
148
|
+
:MK => "Macedonia",
|
149
|
+
:ML => "Mali",
|
150
|
+
:MM => "Myanmar",
|
151
|
+
:MN => "Mongolsko",
|
152
|
+
:MO => "Zvláštní administrativní oblast Číny Macao",
|
153
|
+
:MO => "Macao",
|
154
|
+
:MP => "Severní Mariany",
|
155
|
+
:MQ => "Martinik",
|
156
|
+
:MR => "Mauritánie",
|
157
|
+
:MS => "Montserrat",
|
158
|
+
:MT => "Malta",
|
159
|
+
:MU => "Mauricius",
|
160
|
+
:MV => "Maladivy",
|
161
|
+
:MW => "Malawi",
|
162
|
+
:MX => "Mexiko",
|
163
|
+
:MY => "Malajsie",
|
164
|
+
:MZ => "Mosambik",
|
165
|
+
:NA => "Namibie",
|
166
|
+
:NC => "Nová Kaledonie",
|
167
|
+
:NE => "Niger",
|
168
|
+
:NF => "Norfolk",
|
169
|
+
:NG => "Nigérie",
|
170
|
+
:NI => "Nikaragua",
|
171
|
+
:NL => "Nizozemsko",
|
172
|
+
:NO => "Norsko",
|
173
|
+
:NP => "Nepál",
|
174
|
+
:NR => "Nauru",
|
175
|
+
:NU => "Niue",
|
176
|
+
:NZ => "Nový Zéland",
|
177
|
+
:OM => "Omán",
|
178
|
+
:PA => "Panama",
|
179
|
+
:PE => "Peru",
|
180
|
+
:PF => "Francouzská Polynésie",
|
181
|
+
:PG => "Papua-Nová Guinea",
|
182
|
+
:PH => "Filipíny",
|
183
|
+
:PK => "Pákistán",
|
184
|
+
:PL => "Polsko",
|
185
|
+
:PM => "Svatý Pierre a Miquelon",
|
186
|
+
:PN => "Pitcairn",
|
187
|
+
:PR => "Portoriko",
|
188
|
+
:PS => "Palestinian Territory",
|
189
|
+
:PT => "Portugalsko",
|
190
|
+
:PW => "Palau",
|
191
|
+
:PY => "Paraguay",
|
192
|
+
:QA => "Katar",
|
193
|
+
:QO => "Vnější Oceánie",
|
194
|
+
:QU => "Evropská unie",
|
195
|
+
:RE => "Réunion",
|
196
|
+
:RO => "Rumunsko",
|
197
|
+
:RS => "Srbsko",
|
198
|
+
:RU => "Rusko",
|
199
|
+
:RW => "Rwanda",
|
200
|
+
:SA => "Saúdská Arábie",
|
201
|
+
:SB => "Šalamounovy ostrovy",
|
202
|
+
:SC => "Seychely",
|
203
|
+
:SD => "Súdán",
|
204
|
+
:SE => "Švédsko",
|
205
|
+
:SG => "Singapur",
|
206
|
+
:SH => "Svatá Helena",
|
207
|
+
:SI => "Slovinsko",
|
208
|
+
:SJ => "Svalbard a Jan Mayen",
|
209
|
+
:SK => "Slovensko",
|
210
|
+
:SL => "Sierra Leone",
|
211
|
+
:SM => "San Marino",
|
212
|
+
:SN => "Senegal",
|
213
|
+
:SO => "Somálsko",
|
214
|
+
:SR => "Surinam",
|
215
|
+
:ST => "Svatý Tomáš",
|
216
|
+
:SV => "El Salvador",
|
217
|
+
:SY => "Sýrie",
|
218
|
+
:SZ => "Svazijsko",
|
219
|
+
:TC => "Ostrovy Caicos a Turks",
|
220
|
+
:TD => "Čad",
|
221
|
+
:TF => "Francouzská jižní teritoria",
|
222
|
+
:TG => "Togo",
|
223
|
+
:TH => "Thajsko",
|
224
|
+
:TJ => "Tádžikistán",
|
225
|
+
:TK => "Tokelau",
|
226
|
+
:TL => "Východní Timor",
|
227
|
+
:TM => "Turkmenistán",
|
228
|
+
:TN => "Tunisko",
|
229
|
+
:TO => "Tonga",
|
230
|
+
:TR => "Turecko",
|
231
|
+
:TT => "Trinidad a Tobago",
|
232
|
+
:TV => "Tuvalu",
|
233
|
+
:TW => "Tchaj-wan",
|
234
|
+
:TZ => "Tanzanie",
|
235
|
+
:UA => "Ukrajina",
|
236
|
+
:UG => "Uganda",
|
237
|
+
:UM => "Menší odlehlé ostrovy USA",
|
238
|
+
:US => "Spojené státy",
|
239
|
+
:UY => "Uruguay",
|
240
|
+
:UZ => "Uzbekistán",
|
241
|
+
:VA => "Svatý stolec",
|
242
|
+
:VC => "Svatý Vincent a Grenadiny",
|
243
|
+
:VE => "Venezuela",
|
244
|
+
:VG => "Britské Panenské ostrovy",
|
245
|
+
:VI => "Americké Panenské ostrovy",
|
246
|
+
:VN => "Vietnam",
|
247
|
+
:VU => "Vanuatu",
|
248
|
+
:WF => "Wallis a Futuna",
|
249
|
+
:WS => "Samoa",
|
250
|
+
:YE => "Jemen",
|
251
|
+
:YT => "Mayotte",
|
252
|
+
:ZA => "Jihoafrická republika",
|
253
|
+
:ZM => "Zambie",
|
254
|
+
:ZW => "Zimbabwe",
|
255
|
+
:ZZ => "Neznámá nebo neplatná oblast",
|
256
|
+
}
|
257
|
+
|
258
|
+
}
|
259
|
+
}
|
data/locale/en.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
{ :en => {
|
2
|
+
|
3
|
+
:countries => {
|
4
|
+
:AD => "Andorra",
|
5
|
+
:AE => "United Arab Emirates",
|
6
|
+
:AF => "Afghanistan",
|
7
|
+
:AG => "Antigua and Barbuda",
|
8
|
+
:AI => "Anguilla",
|
9
|
+
:AL => "Albania",
|
10
|
+
:AM => "Armenia",
|
11
|
+
:AN => "Netherlands Antilles",
|
12
|
+
:AO => "Angola",
|
13
|
+
:AQ => "Antarctica",
|
14
|
+
:AR => "Argentina",
|
15
|
+
:AS => "American Samoa",
|
16
|
+
:AT => "Austria",
|
17
|
+
:AU => "Australia",
|
18
|
+
:AW => "Aruba",
|
19
|
+
:AX => "Aland Islands",
|
20
|
+
:AZ => "Azerbaijan",
|
21
|
+
:BA => "Bosnia and Herzegovina",
|
22
|
+
:BB => "Barbados",
|
23
|
+
:BD => "Bangladesh",
|
24
|
+
:BE => "Belgium",
|
25
|
+
:BF => "Burkina Faso",
|
26
|
+
:BG => "Bulgaria",
|
27
|
+
:BH => "Bahrain",
|
28
|
+
:BI => "Burundi",
|
29
|
+
:BJ => "Benin",
|
30
|
+
:BL => "Saint Barthélemy",
|
31
|
+
:BM => "Bermuda",
|
32
|
+
:BN => "Brunei",
|
33
|
+
:BO => "Bolivia",
|
34
|
+
:BQ => "British Antarctic Territory",
|
35
|
+
:BR => "Brazil",
|
36
|
+
:BS => "Bahamas",
|
37
|
+
:BT => "Bhutan",
|
38
|
+
:BV => "Bouvet Island",
|
39
|
+
:BW => "Botswana",
|
40
|
+
:BY => "Belarus",
|
41
|
+
:BZ => "Belize",
|
42
|
+
:CA => "Canada",
|
43
|
+
:CC => "Cocos Islands",
|
44
|
+
:CD => "Congo - Kinshasa",
|
45
|
+
:CF => "Central African Republic",
|
46
|
+
:CG => "Congo - Brazzaville",
|
47
|
+
:CH => "Switzerland",
|
48
|
+
:CI => "Ivory Coast",
|
49
|
+
:CK => "Cook Islands",
|
50
|
+
:CL => "Chile",
|
51
|
+
:CM => "Cameroon",
|
52
|
+
:CN => "China",
|
53
|
+
:CO => "Colombia",
|
54
|
+
:CR => "Costa Rica",
|
55
|
+
:CS => "Serbia and Montenegro",
|
56
|
+
:CT => "Canton and Enderbury Islands",
|
57
|
+
:CU => "Cuba",
|
58
|
+
:CV => "Cape Verde",
|
59
|
+
:CX => "Christmas Island",
|
60
|
+
:CY => "Cyprus",
|
61
|
+
:CZ => "Czech Republic",
|
62
|
+
:DD => "East Germany",
|
63
|
+
:DE => "Germany",
|
64
|
+
:DJ => "Djibouti",
|
65
|
+
:DK => "Denmark",
|
66
|
+
:DM => "Dominica",
|
67
|
+
:DO => "Dominican Republic",
|
68
|
+
:DZ => "Algeria",
|
69
|
+
:EC => "Ecuador",
|
70
|
+
:EE => "Estonia",
|
71
|
+
:EG => "Egypt",
|
72
|
+
:EH => "Western Sahara",
|
73
|
+
:ER => "Eritrea",
|
74
|
+
:ES => "Spain",
|
75
|
+
:ET => "Ethiopia",
|
76
|
+
:FI => "Finland",
|
77
|
+
:FJ => "Fiji",
|
78
|
+
:FK => "Falkland Islands",
|
79
|
+
:FM => "Micronesia",
|
80
|
+
:FO => "Faroe Islands",
|
81
|
+
:FQ => "French Southern and Antarctic Territories",
|
82
|
+
:FR => "France",
|
83
|
+
:FX => "Metropolitan France",
|
84
|
+
:GA => "Gabon",
|
85
|
+
:GB => "United Kingdom",
|
86
|
+
:GD => "Grenada",
|
87
|
+
:GE => "Georgia",
|
88
|
+
:GF => "French Guiana",
|
89
|
+
:GG => "Guernsey",
|
90
|
+
:GH => "Ghana",
|
91
|
+
:GI => "Gibraltar",
|
92
|
+
:GL => "Greenland",
|
93
|
+
:GM => "Gambia",
|
94
|
+
:GN => "Guinea",
|
95
|
+
:GP => "Guadeloupe",
|
96
|
+
:GQ => "Equatorial Guinea",
|
97
|
+
:GR => "Greece",
|
98
|
+
:GS => "South Georgia and the South Sandwich Islands",
|
99
|
+
:GT => "Guatemala",
|
100
|
+
:GU => "Guam",
|
101
|
+
:GW => "Guinea-Bissau",
|
102
|
+
:GY => "Guyana",
|
103
|
+
:HK => "Hong Kong SAR China",
|
104
|
+
:HK => "Hong Kong",
|
105
|
+
:HM => "Heard Island and McDonald Islands",
|
106
|
+
:HN => "Honduras",
|
107
|
+
:HR => "Croatia",
|
108
|
+
:HT => "Haiti",
|
109
|
+
:HU => "Hungary",
|
110
|
+
:ID => "Indonesia",
|
111
|
+
:IE => "Ireland",
|
112
|
+
:IL => "Israel",
|
113
|
+
:IM => "Isle of Man",
|
114
|
+
:IN => "India",
|
115
|
+
:IO => "British Indian Ocean Territory",
|
116
|
+
:IQ => "Iraq",
|
117
|
+
:IR => "Iran",
|
118
|
+
:IS => "Iceland",
|
119
|
+
:IT => "Italy",
|
120
|
+
:JE => "Jersey",
|
121
|
+
:JM => "Jamaica",
|
122
|
+
:JO => "Jordan",
|
123
|
+
:JP => "Japan",
|
124
|
+
:JT => "Johnston Island",
|
125
|
+
:KE => "Kenya",
|
126
|
+
:KG => "Kyrgyzstan",
|
127
|
+
:KH => "Cambodia",
|
128
|
+
:KI => "Kiribati",
|
129
|
+
:KM => "Comoros",
|
130
|
+
:KN => "Saint Kitts and Nevis",
|
131
|
+
:KP => "North Korea",
|
132
|
+
:KR => "South Korea",
|
133
|
+
:KW => "Kuwait",
|
134
|
+
:KY => "Cayman Islands",
|
135
|
+
:KZ => "Kazakhstan",
|
136
|
+
:LA => "Laos",
|
137
|
+
:LB => "Lebanon",
|
138
|
+
:LC => "Saint Lucia",
|
139
|
+
:LI => "Liechtenstein",
|
140
|
+
:LK => "Sri Lanka",
|
141
|
+
:LR => "Liberia",
|
142
|
+
:LS => "Lesotho",
|
143
|
+
:LT => "Lithuania",
|
144
|
+
:LU => "Luxembourg",
|
145
|
+
:LV => "Latvia",
|
146
|
+
:LY => "Libya",
|
147
|
+
:MA => "Morocco",
|
148
|
+
:MC => "Monaco",
|
149
|
+
:MD => "Moldova",
|
150
|
+
:ME => "Montenegro",
|
151
|
+
:MF => "Saint Martin",
|
152
|
+
:MG => "Madagascar",
|
153
|
+
:MH => "Marshall Islands",
|
154
|
+
:MI => "Midway Islands",
|
155
|
+
:MK => "Macedonia",
|
156
|
+
:ML => "Mali",
|
157
|
+
:MM => "Myanmar",
|
158
|
+
:MN => "Mongolia",
|
159
|
+
:MO => "Macau SAR China",
|
160
|
+
:MO => "Macau",
|
161
|
+
:MP => "Northern Mariana Islands",
|
162
|
+
:MQ => "Martinique",
|
163
|
+
:MR => "Mauritania",
|
164
|
+
:MS => "Montserrat",
|
165
|
+
:MT => "Malta",
|
166
|
+
:MU => "Mauritius",
|
167
|
+
:MV => "Maldives",
|
168
|
+
:MW => "Malawi",
|
169
|
+
:MX => "Mexico",
|
170
|
+
:MY => "Malaysia",
|
171
|
+
:MZ => "Mozambique",
|
172
|
+
:NA => "Namibia",
|
173
|
+
:NC => "New Caledonia",
|
174
|
+
:NE => "Niger",
|
175
|
+
:NF => "Norfolk Island",
|
176
|
+
:NG => "Nigeria",
|
177
|
+
:NI => "Nicaragua",
|
178
|
+
:NL => "Netherlands",
|
179
|
+
:NO => "Norway",
|
180
|
+
:NP => "Nepal",
|
181
|
+
:NQ => "Dronning Maud Land",
|
182
|
+
:NR => "Nauru",
|
183
|
+
:NT => "Neutral Zone",
|
184
|
+
:NU => "Niue",
|
185
|
+
:NZ => "New Zealand",
|
186
|
+
:OM => "Oman",
|
187
|
+
:PA => "Panama",
|
188
|
+
:PC => "Pacific Islands Trust Territory",
|
189
|
+
:PE => "Peru",
|
190
|
+
:PF => "French Polynesia",
|
191
|
+
:PG => "Papua New Guinea",
|
192
|
+
:PH => "Philippines",
|
193
|
+
:PK => "Pakistan",
|
194
|
+
:PL => "Poland",
|
195
|
+
:PM => "Saint Pierre and Miquelon",
|
196
|
+
:PN => "Pitcairn",
|
197
|
+
:PR => "Puerto Rico",
|
198
|
+
:PS => "Palestinian Territory",
|
199
|
+
:PT => "Portugal",
|
200
|
+
:PU => "U.S. Miscellaneous Pacific Islands",
|
201
|
+
:PW => "Palau",
|
202
|
+
:PY => "Paraguay",
|
203
|
+
:PZ => "Panama Canal Zone",
|
204
|
+
:QA => "Qatar",
|
205
|
+
:QO => "Outlying Oceania",
|
206
|
+
:QU => "European Union",
|
207
|
+
:RE => "Reunion",
|
208
|
+
:RO => "Romania",
|
209
|
+
:RS => "Serbia",
|
210
|
+
:RU => "Russia",
|
211
|
+
:RW => "Rwanda",
|
212
|
+
:SA => "Saudi Arabia",
|
213
|
+
:SB => "Solomon Islands",
|
214
|
+
:SC => "Seychelles",
|
215
|
+
:SD => "Sudan",
|
216
|
+
:SE => "Sweden",
|
217
|
+
:SG => "Singapore",
|
218
|
+
:SH => "Saint Helena",
|
219
|
+
:SI => "Slovenia",
|
220
|
+
:SJ => "Svalbard and Jan Mayen",
|
221
|
+
:SK => "Slovakia",
|
222
|
+
:SL => "Sierra Leone",
|
223
|
+
:SM => "San Marino",
|
224
|
+
:SN => "Senegal",
|
225
|
+
:SO => "Somalia",
|
226
|
+
:SR => "Suriname",
|
227
|
+
:ST => "Sao Tome and Principe",
|
228
|
+
:SU => "Union of Soviet Socialist Republics",
|
229
|
+
:SV => "El Salvador",
|
230
|
+
:SY => "Syria",
|
231
|
+
:SZ => "Swaziland",
|
232
|
+
:TC => "Turks and Caicos Islands",
|
233
|
+
:TD => "Chad",
|
234
|
+
:TF => "French Southern Territories",
|
235
|
+
:TG => "Togo",
|
236
|
+
:TH => "Thailand",
|
237
|
+
:TJ => "Tajikistan",
|
238
|
+
:TK => "Tokelau",
|
239
|
+
:TL => "East Timor",
|
240
|
+
:TM => "Turkmenistan",
|
241
|
+
:TN => "Tunisia",
|
242
|
+
:TO => "Tonga",
|
243
|
+
:TR => "Turkey",
|
244
|
+
:TT => "Trinidad and Tobago",
|
245
|
+
:TV => "Tuvalu",
|
246
|
+
:TW => "Taiwan",
|
247
|
+
:TZ => "Tanzania",
|
248
|
+
:UA => "Ukraine",
|
249
|
+
:UG => "Uganda",
|
250
|
+
:UM => "United States Minor Outlying Islands",
|
251
|
+
:US => "United States",
|
252
|
+
:UY => "Uruguay",
|
253
|
+
:UZ => "Uzbekistan",
|
254
|
+
:VA => "Vatican",
|
255
|
+
:VC => "Saint Vincent and the Grenadines",
|
256
|
+
:VD => "North Vietnam",
|
257
|
+
:VE => "Venezuela",
|
258
|
+
:VG => "British Virgin Islands",
|
259
|
+
:VI => "U.S. Virgin Islands",
|
260
|
+
:VN => "Vietnam",
|
261
|
+
:VU => "Vanuatu",
|
262
|
+
:WF => "Wallis and Futuna",
|
263
|
+
:WK => "Wake Island",
|
264
|
+
:WS => "Samoa",
|
265
|
+
:YD => "People's Democratic Republic of Yemen",
|
266
|
+
:YE => "Yemen",
|
267
|
+
:YT => "Mayotte",
|
268
|
+
:ZA => "South Africa",
|
269
|
+
:ZM => "Zambia",
|
270
|
+
:ZW => "Zimbabwe",
|
271
|
+
:ZZ => "Unknown or Invalid Region",
|
272
|
+
}
|
273
|
+
|
274
|
+
}
|
275
|
+
}
|
@@ -0,0 +1,132 @@
|
|
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
|
+
# puts localized_country_select(:user, :country)
|
38
|
+
assert localized_country_select(:user, :country) =~
|
39
|
+
Regexp.new(Regexp.escape('<select id="user_country" name="user[country]">')),
|
40
|
+
"Should have proper name for object"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_return_select_tag_with_proper_name
|
44
|
+
# puts localized_country_select_tag( "competition_submission[data][citizenship]", nil)
|
45
|
+
assert localized_country_select_tag( "competition_submission[data][citizenship]", nil) =~
|
46
|
+
Regexp.new(
|
47
|
+
Regexp.escape('<select id="competition_submission_data_citizenship" name="competition_submission[data][citizenship]">') ),
|
48
|
+
"Should have proper name"
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_return_option_tags
|
52
|
+
assert localized_country_select(:user, :country) =~ Regexp.new(Regexp.escape('<option value="ES">Spain</option>'))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_return_localized_option_tags
|
56
|
+
I18n.locale = 'cz'
|
57
|
+
assert localized_country_select(:user, :country) =~ Regexp.new(Regexp.escape('<option value="ES">Španělsko</option>'))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_return_priority_countries_first
|
61
|
+
assert localized_country_options_for_select(nil, [:ES, :CZ]) =~ Regexp.new(
|
62
|
+
Regexp.escape("<option value=\"ES\">Spain</option>\n<option value=\"CZ\">Czech Republic</option><option value=\"\" disabled=\"disabled\">-------------</option>\n<option value=\"AF\">Afghanistan</option>\n"))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_i18n_should_know_about_countries
|
66
|
+
assert_equal 'Spain', I18n.t('ES', :scope => 'countries')
|
67
|
+
I18n.locale = 'cz'
|
68
|
+
assert_equal 'Španělsko', I18n.t('ES', :scope => 'countries')
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_excludes_countries
|
72
|
+
assert_nothing_raised { LocalizedCountrySelect::localized_countries_array(:exclude => :ZZ) }
|
73
|
+
|
74
|
+
assert_block do
|
75
|
+
not LocalizedCountrySelect::localized_countries_array(:exclude => :ZZ).any? {|country| country.last == "ZZ"}
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_block do
|
79
|
+
not LocalizedCountrySelect::localized_countries_array(:exclude => [:ZZ, :US]).any? {|country| country.last == "ZZ" or country.last == "US"}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_localized_countries_array_returns_correctly
|
84
|
+
assert_nothing_raised { LocalizedCountrySelect::localized_countries_array() }
|
85
|
+
# puts LocalizedCountrySelect::localized_countries_array.inspect
|
86
|
+
I18n.locale = 'en'
|
87
|
+
assert_equal 266, LocalizedCountrySelect::localized_countries_array.size
|
88
|
+
assert_equal 'Afghanistan', LocalizedCountrySelect::localized_countries_array.first[0]
|
89
|
+
assert_equal 250, LocalizedCountrySelect::localized_countries_array(locale: :cz).size
|
90
|
+
assert_equal 'Afghánistán', LocalizedCountrySelect::localized_countries_array(locale: :cz).first[0]
|
91
|
+
|
92
|
+
I18n.locale = 'cz'
|
93
|
+
assert_equal 250, LocalizedCountrySelect::localized_countries_array.size
|
94
|
+
assert_equal 'Afghánistán', LocalizedCountrySelect::localized_countries_array.first[0]
|
95
|
+
assert_equal 266, LocalizedCountrySelect::localized_countries_array(locale: :en).size
|
96
|
+
assert_equal 'Afghanistan', LocalizedCountrySelect::localized_countries_array(locale: :en).first[0]
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_priority_countries_returns_correctly_and_in_correct_order
|
100
|
+
assert_nothing_raised { LocalizedCountrySelect::priority_countries_array([:TW, :CN]) }
|
101
|
+
I18n.locale = 'en'
|
102
|
+
assert_equal [ ['Taiwan', 'TW'], ['China', 'CN'] ], LocalizedCountrySelect::priority_countries_array([:TW, :CN])
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_priority_countries_allows_passing_either_symbol_or_string
|
106
|
+
I18n.locale = 'en'
|
107
|
+
assert_equal [ ['United States', 'US'], ['Canada', 'CA'] ], LocalizedCountrySelect::priority_countries_array(['US', 'CA'])
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_priority_countries_allows_passing_upcase_or_lowercase
|
111
|
+
I18n.locale = 'en'
|
112
|
+
assert_equal [ ['United States', 'US'], ['Canada', 'CA'] ], LocalizedCountrySelect::priority_countries_array(['us', 'ca'])
|
113
|
+
assert_equal [ ['United States', 'US'], ['Canada', 'CA'] ], LocalizedCountrySelect::priority_countries_array([:us, :ca])
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_should_list_countries_with_accented_names_in_correct_order
|
117
|
+
I18n.locale = 'cz'
|
118
|
+
assert_match Regexp.new(Regexp.escape(%Q{<option value="BI">Burundi</option>\n<option value="TD">Čad</option>})), localized_country_select(:user, :country)
|
119
|
+
end
|
120
|
+
|
121
|
+
#private
|
122
|
+
|
123
|
+
def setup
|
124
|
+
['cz', 'en'].each do |locale|
|
125
|
+
# I18n.load_translations( File.join(File.dirname(__FILE__), '..', 'locale', "#{locale}.rb") ) # <-- Old style! :)
|
126
|
+
I18n.load_path += Dir[ File.join(File.dirname(__FILE__), '..', 'locale', "#{locale}.rb") ]
|
127
|
+
end
|
128
|
+
# I18n.locale = I18n.default_locale
|
129
|
+
I18n.locale = 'en'
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brainsome_localized_country_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- karmi
|
8
|
+
- mlitwiniuk
|
9
|
+
- LIM SAS
|
10
|
+
- Damien MATHIEU
|
11
|
+
- Julien SANCHEZ
|
12
|
+
- Hervé GAUCHER
|
13
|
+
- RainerBlessing
|
14
|
+
- Brainsome-Developers
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: actionpack
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
type: :runtime
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.0
|
48
|
+
description: Localized "country_select" helper with Rake task for downloading locales
|
49
|
+
from Unicode.org's CLDR
|
50
|
+
email:
|
51
|
+
-
|
52
|
+
- maciej@litwiniuk.net
|
53
|
+
-
|
54
|
+
-
|
55
|
+
-
|
56
|
+
-
|
57
|
+
-
|
58
|
+
-
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- MIT-LICENSE
|
66
|
+
- README.rdoc
|
67
|
+
- Rakefile
|
68
|
+
- install.rb
|
69
|
+
- lib/localized_country_select.rb
|
70
|
+
- lib/localized_country_select/railtie.rb
|
71
|
+
- lib/localized_country_select/version.rb
|
72
|
+
- lib/tasks/localized_country_select_tasks.rake
|
73
|
+
- locale/cz.rb
|
74
|
+
- locale/en.rb
|
75
|
+
- test/localized_country_select_test.rb
|
76
|
+
- uninstall.rb
|
77
|
+
homepage: https://github.com/brainsome-de/localized_country_select
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Localized "country_select" helper with Rake task for downloading locales
|
101
|
+
from Unicode.org's CLDR
|
102
|
+
test_files:
|
103
|
+
- test/localized_country_select_test.rb
|