@@ -118,6 +118,34 END_DESC | |||||
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
|
121 | desc 'Duplicates a key. Exemple rake locales:dup key=foo new_key=bar' | |||
|
122 | task :dup do | |||
|
123 | dir = ENV['DIR'] || './config/locales' | |||
|
124 | files = Dir.glob(File.join(dir,'*.yml')) | |||
|
125 | skips = ENV['skip'] ? Regexp.union(ENV['skip'].split(',')) : nil | |||
|
126 | key = ENV['key'] | |||
|
127 | new_key = ENV['new_key'] | |||
|
128 | abort "Missing key argument" if key.blank? | |||
|
129 | abort "Missing new_key argument" if new_key.blank? | |||
|
130 | ||||
|
131 | files.each do |path| | |||
|
132 | # Skip certain locales | |||
|
133 | (puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips | |||
|
134 | puts "Adding #{new_key} to #{path}" | |||
|
135 | ||||
|
136 | strings = File.read(path) | |||
|
137 | unless strings =~ /^( #{key}: .+)$/ | |||
|
138 | puts "Key not found in #{path}" | |||
|
139 | next | |||
|
140 | end | |||
|
141 | line = $1 | |||
|
142 | ||||
|
143 | File.open(path, 'a') do |file| | |||
|
144 | file.puts(line.sub(key, new_key)) | |||
|
145 | end | |||
|
146 | end | |||
|
147 | end | |||
|
148 | ||||
121 | desc 'Check parsing yaml by psych library on Ruby 1.9.' |
|
149 | desc 'Check parsing yaml by psych library on Ruby 1.9.' | |
122 |
|
150 | |||
123 | # On Fedora 12 and 13, if libyaml-devel is available, |
|
151 | # On Fedora 12 and 13, if libyaml-devel is available, |
General Comments 0
You need to be logged in to leave comments.
Login now