summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-26 17:32:22 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-26 17:32:22 +0000
commit04f9a321b1205d6017c86030eebd6f8b3b93774a (patch)
treed600662941a08f7a285fc7cdb9dc4fae436a5c8a /lib
parentf03e21fb45e534e4747b5b9e21593ffb1b35ae70 (diff)
downloadredmine-04f9a321b1205d6017c86030eebd6f8b3b93774a.tar.gz
redmine-04f9a321b1205d6017c86030eebd6f8b3b93774a.zip
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
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/locales.rake28
1 files changed, 28 insertions, 0 deletions
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,