-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorter.rb
39 lines (32 loc) · 890 Bytes
/
sorter.rb
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
# Sort localization lines in files
# Files format *.strings
# Lines format /^\"[a-zA-Z0-9]+\"\s{,2}=\s{,2}\".+\";$/ Ex: "Day" = "День";
# Other files and format will be ingored
# Shatunov S. MIT License.
# ruby 1.9.2 tested
list = Dir[File.join("./", "*.strings")]
puts "Files found: " + list.to_s
puts
list.each do |file|
buffer = Array.new
unsort = Array.new
File.open(file, 'r') do |f1|
while line = f1.gets
if (line =~ /^\"[a-zA-Z0-9]+\"\s{,2}=\s{,2}\".+\";/)
buffer.push line
else
unsort.push line
end
end
end
buffer = buffer.sort
File.open(file, 'w') do |f1|
unsort.each {|line| f1.write(line)}
buffer.each {|line| f1.write(line)}
end
puts "File " + file
puts "unsorted:" + unsort.to_s
puts "Rewrited lines count: " + (unsort.count + buffer.count).to_s
puts
end
puts "Complete!"