Mercurial > hg > soundsoftware-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
244:8972b600f4fb | 245:051f544170fe |
---|---|
1 desc 'Updates and checks locales against en.yml' | |
2 task :locales do | |
3 %w(locales:update locales:check_interpolation).collect do |task| | |
4 Rake::Task[task].invoke | |
5 end | |
6 end | |
7 | |
1 namespace :locales do | 8 namespace :locales do |
2 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).' |
3 task :update do | 10 task :update do |
4 dir = ENV['DIR'] || './config/locales' | 11 dir = ENV['DIR'] || './config/locales' |
5 | 12 |
24 lang << " #{line}" | 31 lang << " #{line}" |
25 end | 32 end |
26 end | 33 end |
27 | 34 |
28 lang.close | 35 lang.close |
36 end | |
37 end | |
38 | |
39 desc 'Checks interpolation arguments in locals against en.yml' | |
40 task :check_interpolation do | |
41 dir = ENV['DIR'] || './config/locales' | |
42 en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en'] | |
43 files = Dir.glob(File.join(dir,'*.{yaml,yml}')) | |
44 files.each do |file| | |
45 file_strings = YAML.load(File.read(file)) | |
46 file_strings = file_strings[file_strings.keys.first] | |
47 | |
48 file_strings.each do |key, string| | |
49 next unless string.is_a?(String) | |
50 string.scan /%\{\w+\}/ do |match| | |
51 unless en_strings[key].nil? || en_strings[key].include?(match) | |
52 puts "#{file}: #{key} uses #{match} not found in en.yml" | |
53 end | |
54 end | |
55 end | |
29 end | 56 end |
30 end | 57 end |
31 | 58 |
32 desc <<-END_DESC | 59 desc <<-END_DESC |
33 Removes a translation string from all locale file (only works for top-level childless non-multiline keys, probably doesn\'t work on windows). | 60 Removes a translation string from all locale file (only works for top-level childless non-multiline keys, probably doesn\'t work on windows). |