-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
52 lines (44 loc) · 1.06 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
require 'rake'
require 'l18n'
include L18n
desc "Run unit tests"
task "test" do
sh "ruby test.rb"
end
desc "Show all strings avaialable to be translated"
task :strings do
get_matches.each do |m|
puts "\"#{m}\":"
end
end
desc "Get Spanish file including already translated strings"
task :spanish do
dump_yaml("es")
end
desc "Get English file including already translated strings"
task :english do
dump_yaml("en")
end
# If the hash has sorted each, its YAML represention will also be sorted.
def hash_with_sorted_each
hash = Hash.new
def hash.each(&block); keys.sort.each { |k| yield k, self[k] }; end
hash
end
# TODO find a way to keep Yaml in UTF-8. WTF??? I thought this was 2009.
def dump_yaml(lang)
hash = hash_with_sorted_each # for nicer YAML output
get_matches.each do |m|
hash[m.to_s] = get_string(m.to_s, lang)
end
puts hash.to_yaml
end
def get_matches
matches = []
Dir['views/**/*.*'].each do |file|
string = IO.read file
matches += string.scan(/\<\%\=\s?s\(["|'](.+?)['|"]\)\s?\%\>/m)
end
matches.sort!
matches.uniq
end