country-select-engine 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.gitignore +25 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +97 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +105 -0
  6. data/Rakefile +29 -0
  7. data/config/locales/countries.de.yml +268 -0
  8. data/config/locales/countries.en-US.yml +268 -0
  9. data/config/locales/countries.en.yml +268 -0
  10. data/config/locales/countries.es.yml +268 -0
  11. data/config/locales/countries.fr.yml +268 -0
  12. data/config/locales/countries.it.yml +268 -0
  13. data/config/locales/countries.ja.yml +268 -0
  14. data/config/locales/countries.ru.yml +268 -0
  15. data/config/locales/countries.zh-CN.yml +268 -0
  16. data/config/locales/countries.zh-TW.yml +268 -0
  17. data/config/locales/currencies.de.yml +163 -0
  18. data/config/locales/currencies.en-US.yml +163 -0
  19. data/config/locales/currencies.en.yml +163 -0
  20. data/config/locales/currencies.es.yml +163 -0
  21. data/config/locales/currencies.fr.yml +163 -0
  22. data/config/locales/currencies.it.yml +163 -0
  23. data/config/locales/currencies.ja.yml +163 -0
  24. data/config/locales/currencies.ru.yml +163 -0
  25. data/config/locales/currencies.zh-CN.yml +163 -0
  26. data/config/locales/currencies.zh-TW.yml +163 -0
  27. data/config/locales/languages.de.yml +12 -0
  28. data/config/locales/languages.en-US.yml +12 -0
  29. data/config/locales/languages.en.yml +12 -0
  30. data/config/locales/languages.es.yml +12 -0
  31. data/config/locales/languages.fr.yml +12 -0
  32. data/config/locales/languages.it.yml +12 -0
  33. data/config/locales/languages.ja.yml +12 -0
  34. data/config/locales/languages.ru.yml +12 -0
  35. data/config/locales/languages.zh-CN.yml +12 -0
  36. data/config/locales/languages.zh-TW.yml +12 -0
  37. data/config/locales/timezones.de.yml +144 -0
  38. data/config/locales/timezones.en.yml +144 -0
  39. data/config/locales/timezones.es.yml +144 -0
  40. data/config/locales/timezones.fr.yml +144 -0
  41. data/config/locales/timezones.it.yml +144 -0
  42. data/config/locales/timezones.ja.yml +144 -0
  43. data/config/locales/timezones.ru.yml +144 -0
  44. data/config/locales/timezones.zh-CN.yml +144 -0
  45. data/config/locales/timezones.zh-TW.yml +144 -0
  46. data/config/routes.rb +2 -0
  47. data/country-select-engine.gemspec +26 -0
  48. data/lib/content_helper.rb +43 -0
  49. data/lib/country-select-engine/engine.rb +4 -0
  50. data/lib/country-select-engine/version.rb +3 -0
  51. data/lib/country-select-engine.rb +181 -0
  52. data/lib/parse_helper.rb +26 -0
  53. data/lib/tasks/import_locales.rake +72 -0
  54. data/script/convert_cldr.rb +116 -0
  55. data/script/google.yml +143 -0
  56. data/script/google.zh-TW.yml +143 -0
  57. data/script/rails +8 -0
  58. data/script/timezones.yml +144 -0
  59. data/script/translate_timezones.rb +26 -0
  60. data/spec/dummy/README.rdoc +261 -0
  61. data/spec/dummy/Rakefile +7 -0
  62. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  63. data/spec/dummy/app/assets/javascripts/dummy.js +2 -0
  64. data/spec/dummy/app/assets/stylesheets/application.css +14 -0
  65. data/spec/dummy/app/assets/stylesheets/dummy.css +4 -0
  66. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  67. data/spec/dummy/app/controllers/dummy_controller.rb +4 -0
  68. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  69. data/spec/dummy/app/helpers/dummy_helper.rb +2 -0
  70. data/spec/dummy/app/mailers/.gitkeep +0 -0
  71. data/spec/dummy/app/models/.gitkeep +0 -0
  72. data/spec/dummy/app/views/dummy/index.html.erb +41 -0
  73. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  74. data/spec/dummy/config/application.rb +62 -0
  75. data/spec/dummy/config/boot.rb +10 -0
  76. data/spec/dummy/config/database.yml +25 -0
  77. data/spec/dummy/config/environment.rb +5 -0
  78. data/spec/dummy/config/environments/development.rb +37 -0
  79. data/spec/dummy/config/environments/production.rb +67 -0
  80. data/spec/dummy/config/environments/test.rb +37 -0
  81. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/spec/dummy/config/initializers/inflections.rb +15 -0
  83. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  84. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  85. data/spec/dummy/config/initializers/session_store.rb +8 -0
  86. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  87. data/spec/dummy/config/routes.rb +60 -0
  88. data/spec/dummy/config.ru +4 -0
  89. data/spec/dummy/db/development.sqlite3 +0 -0
  90. data/spec/dummy/lib/assets/.gitkeep +0 -0
  91. data/spec/dummy/log/.gitkeep +0 -0
  92. data/spec/dummy/public/404.html +26 -0
  93. data/spec/dummy/public/422.html +26 -0
  94. data/spec/dummy/public/500.html +25 -0
  95. data/spec/dummy/public/favicon.ico +0 -0
  96. data/spec/dummy/script/rails +6 -0
  97. data/spec/localized_country_select_test.rb +134 -0
  98. data/spec/spec_helper.rb +32 -0
  99. data/vendor/assets/images/chosen-sprite.png +0 -0
  100. data/vendor/assets/javascripts/chosen.jquery.min.js +10 -0
  101. data/vendor/assets/stylesheets/chosen.css +396 -0
  102. metadata +209 -0
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "country-select-engine/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "country-select-engine"
9
+ s.version = CountrySelectEngine::VERSION
10
+ s.authors = ["Yen-Ju Chen", "Kristian Mandrup"]
11
+ s.email = ["yjchenx@gmail.com", "kmandrup@gmail.com"]
12
+ s.homepage = ""
13
+ s.summary = "Rails engine for localized_country_select."
14
+ s.description = s.summary
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rails", "~> 3.2.3"
22
+ # s.add_dependency "hpricot"
23
+ # s.add_dependency "jquery-rails"
24
+
25
+ s.add_development_dependency "sqlite3"
26
+ end
@@ -0,0 +1,43 @@
1
+ =begin
2
+ module CountrySelectEngine
3
+ module ContentHelper
4
+ def countries_yaml_content
5
+ countries.inject([]) do |output, country|
6
+ output << " #{country[:code]}: \"#{country[:name]}\""
7
+ output
8
+ end.join("\n")
9
+ end
10
+
11
+ def countries_hash_content
12
+ countries.inject([]) do |output, country|
13
+ output << " :#{country[:code]} => \"#{country[:name]}\","
14
+ output
15
+ end.join("\n")
16
+ end
17
+
18
+ def get_output
19
+ send :"#{file_ext}_output"
20
+ end
21
+
22
+ def yaml_output
23
+ output = %Q{#{locale}:
24
+ countries:
25
+ #{countries_yaml_content}
26
+ }
27
+ end
28
+
29
+ def rb_output
30
+ output = <<HASH
31
+ {
32
+ :#{locale} => {
33
+ :countries => {
34
+ #{countries_hash_content}
35
+ }
36
+ }
37
+ }
38
+ HASH
39
+ end
40
+ alias_method :yml_output, :yaml_output
41
+ end
42
+ end
43
+ =end
@@ -0,0 +1,4 @@
1
+ module CountrySelectEngine
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module CountrySelectEngine
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,181 @@
1
+ require "country-select-engine/engine"
2
+
3
+ # = CountrySelectEngine
4
+ #
5
+ # View helper for displaying select list with countries:
6
+ #
7
+ # localized_country_select(:user, :country)
8
+ #
9
+ # Works just like the default Rails' +country_select+ plugin,
10
+ # but stores countries as
11
+ # country *codes*, not *names*, in the database.
12
+ #
13
+ # You can easily translate country codes in your application like this:
14
+ # <%= I18n.t @user.country, :scope => 'countries' %>
15
+ #
16
+ # Uses the Rails internationalization framework (I18n)
17
+ # for translating the names of countries.
18
+ #
19
+ # Use Rake task <tt>rake import:country_select 'de'</tt>
20
+ # for importing country names
21
+ # from Unicode.org's CLDR repository
22
+ # (http://www.unicode.org/cldr/data/charts/summary/root.html)
23
+ #
24
+ # Code adapted from Rails' default +country_select+ plugin (previously in core)
25
+ # See http://github.com/rails/country_select/tree/master/lib/country_select.rb
26
+ #
27
+ module CountrySelectEngine
28
+ categories = ['currencies', 'countries', 'languages', 'timezones']
29
+ categories.each do |category|
30
+
31
+ # Returns array with codes and localized country names
32
+ # (according to <tt>I18n.locale</tt>)
33
+ # for <tt><option></tt> tags
34
+ class_eval %Q{
35
+ def self.localized_#{category}_array options = {}
36
+ options.reverse_merge!(:sort => true)
37
+ res = []
38
+ list = I18n.translate(:#{category}).each do |key, value|
39
+ res << [self.value_with_symbol(key, value, options), key.to_s] if include_key?(key.to_s, options)
40
+ end
41
+ if options[:sort]
42
+ res.sort_by { |country| country.first.parameterize }
43
+ else
44
+ res
45
+ end
46
+ end
47
+ }
48
+
49
+ def self.value_with_symbol(key, value, options = {})
50
+ if options[:timezone]
51
+ timezone = ActiveSupport::TimeZone[key.to_s]
52
+ if timezone
53
+ offset = "GMT#{ActiveSupport::TimeZone[key.to_s].formatted_offset}"
54
+ if options[:timezone] == :prepend
55
+ return "(#{offset}) #{value}"
56
+ elsif options[:timezone] == :append
57
+ return "#{value} (#{offset})"
58
+ end
59
+ else
60
+ return value
61
+ end
62
+ elsif options[:symbol] == :prepend
63
+ return "#{key.to_s}, #{value}"
64
+ elsif options[:symbol] == :append
65
+ return "#{value} (#{key.to_s})"
66
+ else
67
+ return value
68
+ end
69
+ end
70
+
71
+ def self.include_key?(key, options)
72
+ if options[:only]
73
+ return options[:only].include?(key)
74
+ end
75
+ if options[:except]
76
+ return !options[:except].include?(key)
77
+ end
78
+ true
79
+ end
80
+
81
+ # Return array with codes and localized country names
82
+ # for array of country codes passed as argument
83
+ # == Example
84
+ # priority_countries_array([:TW, :CN])
85
+ # # => [ ['Taiwan', 'TW'], ['China', 'CN'] ]
86
+ class_eval %Q{
87
+ def self.priority_#{category}_array(country_codes=[])
88
+ countries = I18n.translate(:#{category})
89
+ country_codes.map { |code| [countries[code.to_s.to_sym]+' ('+code.to_s+')', code.to_s] }
90
+ end
91
+ }
92
+ end
93
+ end
94
+
95
+ module ActionView
96
+ module Helpers
97
+
98
+ module FormOptionsHelper
99
+ categories = ['currencies', 'countries', 'languages', 'timezones']
100
+
101
+ # Return select and option tags for the given object and method, using +localized_country_options_for_select+
102
+ # to generate the list of option tags. Uses <b>country code</b>, not name as option +value+.
103
+ # Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
104
+ # TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
105
+ categories.each do |category|
106
+ class_eval %Q{
107
+ def localized_#{category.singularize}_select(object, method, priority_countries = nil, options = {}, html_options = {})
108
+ InstanceTag.new(object, method, self, options.delete(:object)).
109
+ to_localized_#{category.singularize}_select_tag(priority_countries, options, html_options)
110
+ end
111
+ }
112
+ end
113
+ alias_method :country_select, :localized_country_select
114
+
115
+ # Return "named" select and option tags according to given arguments.
116
+ # Use +selected_value+ for setting initial value
117
+ # It behaves likes older object-binded brother +localized_country_select+ otherwise
118
+ # TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
119
+ categories.each do |category|
120
+ class_eval %Q{
121
+ def localized_#{category.singularize}_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {})
122
+ select_tag name.to_sym, localized_#{category.singularize}_options_for_select(selected_value, priority_countries).html_safe, html_options.stringify_keys
123
+ end
124
+ }
125
+ end
126
+ alias_method :country_select_tag, :localized_country_select_tag
127
+
128
+ # Returns a string of option tags for countries according to locale. Supply the country code in upper-case ('US', 'DE')
129
+ # as +selected+ to have it marked as the selected option tag.
130
+ # Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
131
+ categories.each do |category|
132
+ class_eval %Q{
133
+ def localized_#{category.singularize}_options_for_select(selected = nil, priority_countries = nil, options = {})
134
+ country_options = ""
135
+ if priority_countries
136
+ country_options += options_for_select(CountrySelectEngine::priority_#{category}_array(priority_countries), selected)
137
+ country_options += "<option value='' disabled='disabled'>-------------</option>\n"
138
+ return country_options + options_for_select(CountrySelectEngine::localized_#{category}_array(options) - CountrySelectEngine::priority_#{category}_array(priority_countries), selected)
139
+ else
140
+ return country_options + options_for_select(CountrySelectEngine::localized_#{category}_array(options), selected)
141
+ end
142
+ end
143
+ }
144
+ end
145
+ alias_method :country_options_for_select, :localized_country_options_for_select
146
+
147
+ end
148
+
149
+ class InstanceTag
150
+ categories = ['currencies', 'countries', 'languages', 'timezones']
151
+ categories.each do |category|
152
+ class_eval %Q{
153
+ def to_localized_#{category.singularize}_select_tag(priority_countries, options, html_options)
154
+ html_options = html_options.stringify_keys
155
+ add_default_name_and_id(html_options)
156
+ value = options.has_key?(:selected) ? options[:selected] : value(object)
157
+ content_tag("select",
158
+ add_options(
159
+ localized_#{category.singularize}_options_for_select(value, priority_countries, options).html_safe,
160
+ options, value
161
+ ), html_options
162
+ )
163
+ end
164
+ }
165
+ end
166
+ end
167
+
168
+ class FormBuilder
169
+ categories = ['currencies', 'countries', 'languages', 'timezones']
170
+ categories.each do |category|
171
+ class_eval %Q{
172
+ def localized_#{category.singularize}_select(method, priority_countries = nil, options = {}, html_options = {})
173
+ @template.localized_#{category.singularize}_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
174
+ end
175
+ }
176
+ end
177
+ alias_method :country_select, :localized_country_select
178
+ end
179
+
180
+ end
181
+ end
@@ -0,0 +1,26 @@
1
+ =begin
2
+ module CountrySelectEngine
3
+ module ParseHelper
4
+ def get_code row
5
+ code = row.search("td[@class='g']").inner_text
6
+ code[-code.size, 2]
7
+ end
8
+
9
+ def get_name row
10
+ row.search("td[@class='v']").first.inner_text
11
+ end
12
+
13
+ def country_row? row
14
+ row.search("td[@class='n']") && n_row?(row) && g_row?(row)
15
+ end
16
+
17
+ def n_row? row
18
+ row.search("td[@class='n']").inner_html =~ /^namesterritory$/
19
+ end
20
+
21
+ def g_row? row
22
+ row.search("td[@class='g']").inner_html =~ /^[A-Z]{2}/
23
+ end
24
+ end
25
+ end
26
+ =end
@@ -0,0 +1,72 @@
1
+ =begin
2
+ require 'parse_helper'
3
+ require 'content_helper'
4
+ require 'hpricot'
5
+ require 'open-uri'
6
+
7
+ class CountrySelectEngine::Importer
8
+ include CountrySelectEngine::ParseHelper
9
+ include CountrySelectEngine::ContentHelper
10
+
11
+ def locale
12
+ @locale
13
+ end
14
+
15
+ def countries
16
+ @countries
17
+ end
18
+
19
+ def import(locales)
20
+ if locales.is_a?(String)
21
+ locales = locales.split(' ')
22
+ end
23
+ locales.each do |locale|
24
+ locale = locale.to_s
25
+ @locale = locale
26
+ # ----- Get the CLDR HTML ------
27
+ begin
28
+ puts "... getting the HTML file for locale '#{locale}'"
29
+ doc = Hpricot( open("http://www.unicode.org/cldr/data/charts/summary/#{locale}.html") )
30
+ rescue => e
31
+ puts "[!] Invalid locale name '#{locale}'! Not found in CLDR (#{e})"
32
+ exit 0
33
+ end
34
+
35
+ # ----- Parse the HTML with Hpricot ----
36
+ puts "... parsing the HTML file"
37
+ @countries = [] # reset countries list
38
+ doc.search("//tr").each do |row|
39
+ next if !country_row?(row)
40
+ countries << { :code => get_code(row).to_sym, :name => get_name(row).to_s }
41
+ end
42
+
43
+ # ----- Write the parsed values into file -----
44
+ puts "\n... writing the output"
45
+ filename = File.join(Rails.root, 'config', 'locales', "countries.#{locale}.yml")
46
+ puts filename
47
+ filename += '.NEW' if File.exists?(filename) # Append 'NEW' if file exists
48
+ # File.open(filename, 'w+') { |f| f << get_output }
49
+ File.open(filename, 'w+') { |f| f << yaml_output }
50
+
51
+ puts "\n---\nWritten values for the '#{locale}' into file: #{filename}\n"
52
+ end
53
+ end
54
+ end
55
+ =end
56
+
57
+ =begin
58
+ task :find_place_by_google, :begin, :end, :needs => :environment do |t, args|
59
+ srand Time.now.to_i
60
+ puts args
61
+ (args.begin..args.end).each do |n|
62
+ =end
63
+
64
+ =begin
65
+ namespace :country_select do
66
+ desc 'import locales'
67
+ task :import_locales, [:locales] do |t, args|
68
+ puts args
69
+ CountrySelectEngine::Importer.new.import(args.locales)
70
+ end
71
+ end
72
+ =end
@@ -0,0 +1,116 @@
1
+ require 'yaml'
2
+
3
+ # This script take the output of `ruby-cldr export --merge`,
4
+ # and convert into Rails locales for countries, languages and currencies.
5
+ #
6
+ # https://github.com/svenfuchs/rails-i18n
7
+ # http://people.w3.org/rishida/utils/subtags/index.php
8
+ available_currencies = ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS",
9
+ "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN",
10
+ "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD",
11
+ "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF",
12
+ "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE",
13
+ "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN",
14
+ "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS",
15
+ "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL",
16
+ "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD",
17
+ "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS",
18
+ "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT",
19
+ "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL",
20
+ "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT",
21
+ "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR",
22
+ "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD",
23
+ "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN",
24
+ "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR",
25
+ "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SKK",
26
+ "SLL", "SOS", "SRD", "STD", "SVC", "SYP", "SZL",
27
+ "THB", "TJS", "TMM", "TND", "TOP", "TRY", "TTD",
28
+ "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS",
29
+ "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XOF",
30
+ "XPF", "YER", "ZAR", "ZMK", "ZWD", "EEK", "YEN", "GHC"]
31
+
32
+ =begin
33
+ locales = {
34
+ ar, az, bg, bn-IN, bs, ca, cs, csb, cy, da, de-AT, de-CH, dsb, el, en-AU, en-GB, en-IN, eo, es-AR, es-CL, es-CO, es-MX, es-PE, et, eu, fa, fi, fr-CA, fr-CH, fur, gl-ES, gsw-CH, he, hi, hi-IN, hr, hsb, hu, id, is, kn, ko, lo, lt, lv, mk, mn, nb, nl, nn, pl, pt-BR, pt-PT, rm, ro, sk, sl, sr, sr-Latn, sv-SE, sw, th, tl, tr, uk, vi, wo
35
+ }
36
+ =end
37
+ locales = {
38
+ 'de' => { :locale => 'de', :language => 'de' },
39
+ 'en' => { :locale => 'en', :language => 'en' },
40
+ 'en-US' => { :locale => 'en-US', :language => 'en-US' },
41
+ 'es' => { :locale => 'es', :language => 'es' },
42
+ 'fr' => { :locale => 'fr', :language => 'fr' },
43
+ 'it' => { :locale => 'it', :language => 'it' },
44
+ 'ja' => { :locale => 'ja', :language => 'ja' },
45
+ 'ru' => { :locale => 'ru', :language => 'ru' },
46
+ 'zh-CN' => { :locale => 'zh-Hans-CN', :language => 'zh-Hans' },
47
+ 'zh-TW' => { :locale => 'zh-Hant-TW', :language => 'zh-Hant' }
48
+ }
49
+
50
+ data_path = '../ruby-cldr/data/'
51
+ output_path = 'config/locales/' # must be created
52
+ currency_yaml = 'currencies.yml'
53
+ language_yaml = 'languages.yml'
54
+ country_yaml = 'territories.yml'
55
+
56
+ # currencies
57
+ locales.each do |k, v|
58
+ p = data_path+v[:locale]+'/'+currency_yaml
59
+ puts "read #{p}"
60
+ data = YAML.load_file(p)
61
+ list = {}
62
+ data[v[:locale]]['currencies'].each do |x, y|
63
+ list[x] = y['one'] if available_currencies.include?(x.upcase)
64
+ end
65
+ output = {k => {'currencies' => list}}
66
+ o = output_path+'currencies.'+k+'.yml'
67
+ puts "write #{o}"
68
+ s = YAML.dump(output)
69
+ s = s.lines.to_a[1..-1].join
70
+ f = File.open(o, 'w')
71
+ f.write(s)
72
+ f.close
73
+ end
74
+
75
+ # languages
76
+ locales.each do |k, v|
77
+ p = data_path+v[:locale]+'/'+language_yaml
78
+ puts "read #{p}"
79
+ data = YAML.load_file(p)
80
+ list = {}
81
+ reverse_lookup = {}
82
+ locales.each do |x, y|
83
+ reverse_lookup[y[:language]] = x
84
+ end
85
+ puts reverse_lookup
86
+ data[v[:locale]]['languages'].each do |x, y|
87
+ list[reverse_lookup[x]] = y if reverse_lookup.keys.include?(x)
88
+ end
89
+ output = {k => {'languages' => list}}
90
+ o = output_path+'languages.'+k+'.yml'
91
+ puts "write #{o}"
92
+ s = YAML.dump(output)
93
+ s = s.lines.to_a[1..-1].join
94
+ f = File.open(o, 'w')
95
+ f.write(s)
96
+ f.close
97
+ end
98
+
99
+ # countries
100
+ locales.each do |k, v|
101
+ p = data_path+v[:locale]+'/'+country_yaml
102
+ puts "read #{p}"
103
+ data = YAML.load_file(p)
104
+ list = {}
105
+ data[v[:locale]]['territories'].each do |x, y|
106
+ list[x] = y if (x.is_a?(String) && x.length == 2)
107
+ end
108
+ output = {k => {'countries' => list}}
109
+ o = output_path+'countries.'+k+'.yml'
110
+ puts "write #{o}"
111
+ s = YAML.dump(output)
112
+ s = s.lines.to_a[1..-1].join
113
+ f = File.open(o, 'w')
114
+ f.write(s)
115
+ f.close
116
+ end
data/script/google.yml ADDED
@@ -0,0 +1,143 @@
1
+ timezones:
2
+ - International Date Line West
3
+ - Midway Island
4
+ - Samoa
5
+ - Hawaii
6
+ - Alaska
7
+ - Pacific Time (US & Canada)
8
+ - Tijuana
9
+ - Mountain Time (US & Canada)
10
+ - Arizona
11
+ - Chihuahua
12
+ - Mazatlan
13
+ - Central Time (US & Canada)
14
+ - Saskatchewan
15
+ - Guadalajara
16
+ - Mexico City
17
+ - Monterrey
18
+ - Central America
19
+ - Eastern Time (US & Canada)
20
+ - Indiana (East)
21
+ - Bogota
22
+ - Lima
23
+ - Quito
24
+ - Atlantic Time (Canada)
25
+ - Caracas
26
+ - La Paz
27
+ - Santiago
28
+ - Newfoundland
29
+ - Brasilia
30
+ - Buenos Aires
31
+ - Georgetown
32
+ - Greenland
33
+ - Mid-Atlantic
34
+ - Azores
35
+ - Cape Verde Is.
36
+ - Dublin
37
+ - Edinburgh
38
+ - Lisbon
39
+ - London
40
+ - Casablanca
41
+ - Monrovia
42
+ - UTC
43
+ - Belgrade
44
+ - Bratislava
45
+ - Budapest
46
+ - Ljubljana
47
+ - Prague
48
+ - Sarajevo
49
+ - Skopje
50
+ - Warsaw
51
+ - Zagreb
52
+ - Brussels
53
+ - Copenhagen
54
+ - Madrid
55
+ - Paris
56
+ - Amsterdam
57
+ - Berlin
58
+ - Bern
59
+ - Rome
60
+ - Stockholm
61
+ - Vienna
62
+ - West Central Africa
63
+ - Bucharest
64
+ - Cairo
65
+ - Helsinki
66
+ - Kyev
67
+ - Riga
68
+ - Sofia
69
+ - Tallinn
70
+ - Vilnius
71
+ - Athens
72
+ - Istanbul
73
+ - Minsk
74
+ - Jerusalem
75
+ - Harare
76
+ - Pretoria
77
+ - Moscow
78
+ - St. Petersburg
79
+ - Volgograd
80
+ - Kuwait
81
+ - Riyadh
82
+ - Nairobi
83
+ - Baghdad
84
+ - Tehran
85
+ - Abu Dhabi
86
+ - Muscat
87
+ - Baku
88
+ - Tbilisi
89
+ - Yerevan
90
+ - Kabul
91
+ - Ekaterinburg
92
+ - Islamabad
93
+ - Karachi
94
+ - Tashkent
95
+ - Chennai
96
+ - Kolkata
97
+ - Mumbai
98
+ - New Delhi
99
+ - Kathmandu
100
+ - Astana
101
+ - Dhaka
102
+ - Sri Jayawardenepura
103
+ - Almaty
104
+ - Novosibirsk
105
+ - Rangoon
106
+ - Bangkok
107
+ - Hanoi
108
+ - Jakarta
109
+ - Krasnoyarsk
110
+ - Beijing
111
+ - Chongqing
112
+ - Hong Kong
113
+ - Urumqi
114
+ - Kuala Lumpur
115
+ - Singapore
116
+ - Taipei
117
+ - Perth
118
+ - Irkutsk
119
+ - Ulaan Bataar
120
+ - Seoul
121
+ - Osaka
122
+ - Sapporo
123
+ - Tokyo
124
+ - Yakutsk
125
+ - Darwin
126
+ - Adelaide
127
+ - Canberra
128
+ - Melbourne
129
+ - Sydney
130
+ - Brisbane
131
+ - Hobart
132
+ - Vladivostok
133
+ - Guam
134
+ - Port Moresby
135
+ - Magadan
136
+ - Solomon Is.
137
+ - New Caledonia
138
+ - Fiji
139
+ - Kamchatka
140
+ - Marshall Is.
141
+ - Auckland
142
+ - Wellington
143
+ - Nuku'alofa