Guest User

Untitled

a guest
May 26th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. task :missing_translations => :environment do
  2. @missing_translation_count = 0
  3. for locale in I18n.load_path
  4. look_for_candidates(File.basename(locale,".*"))
  5. end
  6. puts "Total missing translations: #{@missing_translation_count}"
  7. end
  8.  
  9. def look_for_candidates(locale, dir="#{RAILS_ROOT}/app")
  10. entries = Dir.entries(dir) - [".", "..", ".svn", ".git"]
  11. for entry in entries
  12. real_entry = File.join(dir, entry)
  13. if File.directory?(real_entry)
  14. look_for_candidates(locale, real_entry)
  15. else
  16. puts "\n\nChecking for translations in #{real_entry}:"
  17. # dunno, guess some people may use the actual method rather than it's shorter brother
  18. translations = File.readlines(real_entry).to_s.scan(/\s[t|translate]\(.*?\)/)
  19. for translation in translations
  20. translated_to = I18n.t(translation.gsub(/^\s[t|translate]/, "").gsub(/[\(|\)|:]/, "").gsub(/(,.*)/, "").to_sym, :locale => locale)
  21. if translated_to.include?("translation missing:")
  22. @missing_translation_count += 1
  23. puts "mTRANSLATION MISSING FOR: #{translation} (locale: #{locale}) in #{real_entry}"
  24. end
  25. end
  26. end
  27. end
  28. end
Add Comment
Please, Sign In to add comment