@@ -1,53 +1,53 | |||
|
1 | 1 | namespace :gloc do |
|
2 | 2 | desc 'Sorts the keys in the lang ymls' |
|
3 | 3 | task :sort do |
|
4 | 4 | dir = ENV['DIR'] || '{.,vendor/plugins/*}/lang' |
|
5 | 5 | puts "Processing directory #{dir}" |
|
6 | 6 | files = Dir.glob(File.join(dir,'*.{yaml,yml}')) |
|
7 | 7 | puts 'No files found.' if files.empty? |
|
8 | 8 | files.each {|file| |
|
9 | 9 | puts "Sorting file: #{file}" |
|
10 | 10 | header = [] |
|
11 | 11 | content = IO.readlines(file) |
|
12 | 12 | content.each {|line| line.gsub!(/[\s\r\n\t]+$/,'')} |
|
13 | 13 | content.delete_if {|line| line==''} |
|
14 | 14 | tmp= [] |
|
15 | 15 | content.each {|x| tmp << x unless tmp.include?(x)} |
|
16 | 16 | content= tmp |
|
17 | 17 | header << content.shift if !content.empty? && content[0] =~ /^file_charset:/ |
|
18 | 18 | content.sort! |
|
19 | 19 | filebak = "#{file}.bak" |
|
20 | 20 | File.rename file, filebak |
|
21 | 21 | File.open(file, 'w') {|fout| fout << header.join("\n") << content.join("\n") << "\n"} |
|
22 | 22 | File.delete filebak |
|
23 | 23 | # Report duplicates |
|
24 | 24 | count= {} |
|
25 | 25 | content.map {|x| x.gsub(/:.+$/, '') }.each {|x| count[x] ||= 0; count[x] += 1} |
|
26 | 26 | count.delete_if {|k,v|v==1} |
|
27 | 27 | puts count.keys.sort.map{|x|" WARNING: Duplicate key '#{x}' (#{count[x]} occurances)"}.join("\n") unless count.empty? |
|
28 | 28 | } |
|
29 | 29 | end |
|
30 | 30 | |
|
31 |
desc 'Updates language files based on e |
|
|
31 | desc 'Updates language files based on en.yml content' | |
|
32 | 32 | task :update do |
|
33 | 33 | dir = ENV['DIR'] || './lang' |
|
34 | 34 | |
|
35 | 35 | en_strings = {} |
|
36 | 36 | en_file = File.open(File.join(dir,'en.yml'), 'r') |
|
37 | 37 | en_file.each_line {|line| en_strings[$1] = $2 if line =~ %r{^([\w_]+):\s(.+)$} } |
|
38 | 38 | en_file.close |
|
39 | 39 | |
|
40 | 40 | files = Dir.glob(File.join(dir,'*.{yaml,yml}')) |
|
41 | 41 | files.each do |file| |
|
42 | 42 | puts "Updating file #{file}" |
|
43 | 43 | keys = IO.readlines(file).collect {|line| $1 if line =~ %r{^([\w_]+):\s(.+)$} }.compact |
|
44 | 44 | lang = File.open(file, 'a') |
|
45 | 45 | en_strings.each do |key, str| |
|
46 | 46 | next if keys.include?(key) |
|
47 | 47 | puts "added: #{key}" |
|
48 | 48 | lang << "#{key}: #{str}\n" |
|
49 | 49 | end |
|
50 | 50 | lang.close |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | end No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now