diff lib/tasks/.svn/text-base/locales.rake.svn-base @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 94944d00e43c
children cbce1fd3b1b7
line wrap: on
line diff
--- a/lib/tasks/.svn/text-base/locales.rake.svn-base	Thu Mar 03 11:40:10 2011 +0000
+++ b/lib/tasks/.svn/text-base/locales.rake.svn-base	Thu Mar 03 11:42:28 2011 +0000
@@ -1,3 +1,10 @@
+desc 'Updates and checks locales against en.yml'
+task :locales do
+  %w(locales:update locales:check_interpolation).collect do |task|
+    Rake::Task[task].invoke
+  end
+end
+
 namespace :locales do
   desc 'Updates language files based on en.yml content (only works for new top level keys).'
   task :update do
@@ -28,6 +35,26 @@
       lang.close
     end
   end
+  
+  desc 'Checks interpolation arguments in locals against en.yml'
+  task :check_interpolation do
+    dir = ENV['DIR'] || './config/locales'
+    en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en']
+    files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
+    files.each do |file|
+      file_strings = YAML.load(File.read(file))
+      file_strings = file_strings[file_strings.keys.first]
+      
+      file_strings.each do |key, string|
+        next unless string.is_a?(String)
+        string.scan /%\{\w+\}/ do |match|
+          unless en_strings[key].nil? || en_strings[key].include?(match)
+            puts "#{file}: #{key} uses #{match} not found in en.yml"
+          end
+        end
+      end
+    end
+  end
 
   desc <<-END_DESC
 Removes a translation string from all locale file (only works for top-level childless non-multiline keys, probably doesn\'t work on windows).