From 04f9a321b1205d6017c86030eebd6f8b3b93774a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 26 Jul 2012 17:32:22 +0000 Subject: Adds a task to duplicate a string in locales. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10080 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/tasks/locales.rake | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/tasks') diff --git a/lib/tasks/locales.rake b/lib/tasks/locales.rake index 081acf60a..8ad011881 100644 --- a/lib/tasks/locales.rake +++ b/lib/tasks/locales.rake @@ -118,6 +118,34 @@ END_DESC end end + desc 'Duplicates a key. Exemple rake locales:dup key=foo new_key=bar' + task :dup do + dir = ENV['DIR'] || './config/locales' + files = Dir.glob(File.join(dir,'*.yml')) + skips = ENV['skip'] ? Regexp.union(ENV['skip'].split(',')) : nil + key = ENV['key'] + new_key = ENV['new_key'] + abort "Missing key argument" if key.blank? + abort "Missing new_key argument" if new_key.blank? + + files.each do |path| + # Skip certain locales + (puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips + puts "Adding #{new_key} to #{path}" + + strings = File.read(path) + unless strings =~ /^( #{key}: .+)$/ + puts "Key not found in #{path}" + next + end + line = $1 + + File.open(path, 'a') do |file| + file.puts(line.sub(key, new_key)) + end + end + end + desc 'Check parsing yaml by psych library on Ruby 1.9.' # On Fedora 12 and 13, if libyaml-devel is available, -- cgit v1.2.3