##// END OF EJS Templates
remove trailing white-spaces from lib/tasks/locales.rake....
Toshi MARUYAMA -
r5604:2714f6bcacb3
parent child
Show More
@@ -9,21 +9,21 namespace :locales do
9 desc 'Updates language files based on en.yml content (only works for new top level keys).'
9 desc 'Updates language files based on en.yml content (only works for new top level keys).'
10 task :update do
10 task :update do
11 dir = ENV['DIR'] || './config/locales'
11 dir = ENV['DIR'] || './config/locales'
12
12
13 en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en']
13 en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en']
14
14
15 files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
15 files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
16 files.each do |file|
16 files.each do |file|
17 puts "Updating file #{file}"
17 puts "Updating file #{file}"
18 file_strings = YAML.load(File.read(file))
18 file_strings = YAML.load(File.read(file))
19 file_strings = file_strings[file_strings.keys.first]
19 file_strings = file_strings[file_strings.keys.first]
20
20
21 missing_keys = en_strings.keys - file_strings.keys
21 missing_keys = en_strings.keys - file_strings.keys
22 next if missing_keys.empty?
22 next if missing_keys.empty?
23
23
24 puts "==> Missing #{missing_keys.size} keys (#{missing_keys.join(', ')})"
24 puts "==> Missing #{missing_keys.size} keys (#{missing_keys.join(', ')})"
25 lang = File.open(file, 'a')
25 lang = File.open(file, 'a')
26
26
27 missing_keys.each do |key|
27 missing_keys.each do |key|
28 {key => en_strings[key]}.to_yaml.each_line do |line|
28 {key => en_strings[key]}.to_yaml.each_line do |line|
29 next if line =~ /^---/ || line.empty?
29 next if line =~ /^---/ || line.empty?
@@ -31,11 +31,11 namespace :locales do
31 lang << " #{line}"
31 lang << " #{line}"
32 end
32 end
33 end
33 end
34
34
35 lang.close
35 lang.close
36 end
36 end
37 end
37 end
38
38
39 desc 'Checks interpolation arguments in locals against en.yml'
39 desc 'Checks interpolation arguments in locals against en.yml'
40 task :check_interpolation do
40 task :check_interpolation do
41 dir = ENV['DIR'] || './config/locales'
41 dir = ENV['DIR'] || './config/locales'
@@ -44,7 +44,7 namespace :locales do
44 files.each do |file|
44 files.each do |file|
45 file_strings = YAML.load(File.read(file))
45 file_strings = YAML.load(File.read(file))
46 file_strings = file_strings[file_strings.keys.first]
46 file_strings = file_strings[file_strings.keys.first]
47
47
48 file_strings.each do |key, string|
48 file_strings.each do |key, string|
49 next unless string.is_a?(String)
49 next unless string.is_a?(String)
50 string.scan /%\{\w+\}/ do |match|
50 string.scan /%\{\w+\}/ do |match|
@@ -71,7 +71,7 END_DESC
71 deletes = ENV['key'] ? Regexp.union(ENV['key'].split(',')) : nil
71 deletes = ENV['key'] ? Regexp.union(ENV['key'].split(',')) : nil
72 # Ignore multiline keys (begin with | or >) and keys with children (nothing meaningful after :)
72 # Ignore multiline keys (begin with | or >) and keys with children (nothing meaningful after :)
73 delete_regex = /\A #{deletes}: +[^\|>\s#].*\z/
73 delete_regex = /\A #{deletes}: +[^\|>\s#].*\z/
74
74
75 files.each do |path|
75 files.each do |path|
76 # Skip certain locales
76 # Skip certain locales
77 (puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips
77 (puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips
@@ -80,7 +80,7 END_DESC
80 File.open(path, 'w') {|file| orig_content.each_line {|line| file.puts line unless line.chomp =~ delete_regex}}
80 File.open(path, 'w') {|file| orig_content.each_line {|line| file.puts line unless line.chomp =~ delete_regex}}
81 end
81 end
82 end
82 end
83
83
84 desc <<-END_DESC
84 desc <<-END_DESC
85 Adds a new top-level translation string to all locale file (only works for childless keys, probably doesn\'t work on windows, doesn't check for duplicates).
85 Adds a new top-level translation string to all locale file (only works for childless keys, probably doesn\'t work on windows, doesn't check for duplicates).
86
86
General Comments 0
You need to be logged in to leave comments. Login now