Created
February 27, 2012 08:44
-
-
Save iboard/1922608 to your computer and use it in GitHub Desktop.
Rake-Task to find undefined locale-keys in a rails project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding : utf-8 -*- | |
namespace :locales do | |
desc "Find undefined locales" | |
task :undefined_locales => :environment do | |
used_strings = [] | |
Dir['**/*'].each do |file| | |
if File::ftype(file) == "file" | |
begin | |
File::read(file).each_line do |line| | |
line.gsub( /t\(\:(\S+)\)/ ) do |x| | |
used_strings << x.gsub(/t\(\:/,'').gsub(/\)$/,'') | |
end | |
end | |
rescue => e | |
# ignore | |
end | |
end | |
end | |
locale_en = YAML::load( File::read( 'config/locales/en.yml') )['en'] | |
defined_keys = [] | |
not_defined_keys = [] | |
used_strings.each do |key| | |
if locale_en[key].present? | |
defined_keys << key | |
else | |
not_defined_keys << key | |
end | |
end | |
if not_defined_keys.any? | |
puts "NOT DEFINED KEYS:" | |
not_defined_keys.uniq.sort.each do |key| | |
puts " #{key}: #{key.to_s.humanize}" | |
end | |
else | |
puts "ALL KEYS DEFINED" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment