forked from grosser/i18n_data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
78 lines (69 loc) · 2.23 KB
/
Rakefile
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'bump/tasks'
$LOAD_PATH << "lib"
require 'i18n_data'
task :default do
sh "rspec --warnings spec/"
end
desc "write all languages to output"
task :all_languages do
I18nData.languages.keys.each do |lc|
`rake languages LANGUAGE=#{lc}`
end
end
desc "write languages to output/languages_{language}"
task :languages do
raise unless language = ENV['LANGUAGE']
`mkdir -p output`
data = I18nData.languages(language.upcase)
File.open("output/languages_#{language.downcase}.yml",'w') {|f|f.puts data.to_yaml}
end
desc "write all countries to output"
task :all_countries do
I18nData.languages.keys.each do |lc|
`rake countries LANGUAGE=#{lc}`
end
end
desc "write countries to output/countries_{language}"
task :countries do
raise unless language = ENV['LANGUAGE']
`mkdir -p output`
data = I18nData.countries(language.upcase)
File.open("output/countries_#{language.downcase}.yml",'w') {|f|f.puts data.to_yaml}
end
desc "write example output, just to show off :D"
task :example_output do
`mkdir -p example_output`
#all names for germany, france, united kingdom and unites states
['DE','FR','GB','US'].each do |cc|
names = I18nData.languages.keys.map do |lc|
begin
[I18nData.countries(lc)[cc], I18nData.languages[lc]]
rescue I18nData::NoTranslationAvailable
nil
end
end
File.open("example_output/all_names_for_#{cc}.txt",'w') do |f|
f.puts names.reject(&:nil?).map{|x|x*" ---- "} * "\n"
end
end
end
desc "show stats"
task :stats do
dir = "cache/file_data_provider"
[:languages, :countries].each do |type|
files = FileList["#{dir}/#{type}*"]
lines = File.readlines(files.first).reject{|l|l.empty?}
puts "#{lines.size} #{type} in #{files.size} languages"
end
end
desc "write cache for I18nData::FileDataProvider"
task :write_cache_for_file_data_provider do
raise "use 1.9+, we need sorted hashes or diff is giant" if RUBY_VERSION < "1.9"
require 'i18n_data/file_data_provider'
require 'i18n_data/live_data_provider'
sh "rm -rf cache/file_data_provider" # clean everything so old stuff goes away
I18nData::LiveDataProvider.clear_cache
I18nData::FileDataProvider.write_cache(I18nData::LiveDataProvider)
end