forked from countries/countries
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
60 lines (48 loc) · 1.52 KB
/
Rakefile
File metadata and controls
60 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env rake
require 'bundler/gem_tasks'
require 'rake'
require 'rspec/core/rake_task'
desc 'Run all examples'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w(--color --warnings)
end
task default: [:spec]
desc 'Test and Clean YAML files'
task :clean_yaml do
require 'yaml'
d = Dir['**/*.yaml']
d.each do |file|
begin
puts "checking : #{file}"
data = YAML.load_file(file)
File.open(file, 'w') { |f| f.write data.to_yaml }
rescue
puts "failed to read #{file}: #{$ERROR_INFO}"
end
end
end
desc 'Cache Translations'
task :cache_translations do
require 'yaml'
require 'i18n_data'
codes = YAML.load_file(File.join(File.dirname(__FILE__), 'lib', 'data', 'countries.yaml')) || {}
data = {}
empty_translations_hash = {}
# I18nData.languages.each { |l, _n| empty_translations_hash[l.downcase] = nil }
I18nData.languages.keys.each do |locale|
begin
local_names = I18nData.countries(locale)
rescue I18nData::NoTranslationAvailable
next
end
codes.each do |alpha2|
data[alpha2] ||= {}
data[alpha2]['translations'] ||= empty_translations_hash.dup
data[alpha2]['translations'][locale.downcase] = local_names[alpha2]
data[alpha2]['translated_names'] ||= []
data[alpha2]['translated_names'] << local_names[alpha2]
data[alpha2]['translated_names'] = data[alpha2]['translated_names'].uniq
end
end
File.open(File.join(File.dirname(__FILE__), 'lib', 'cache', 'translations.yaml'), 'w+') { |f| f.write data.to_yaml }
end