Skip to content

Instantly share code, notes, and snippets.

@conorh
Created November 18, 2009 16:21
Show Gist options
  • Save conorh/238011 to your computer and use it in GitHub Desktop.
Save conorh/238011 to your computer and use it in GitHub Desktop.
Check for missing i18n SimpleBackend translations
#!/usr/bin/env ruby
# This is intended for the I18n SimpleBackend. It checks to see that every string
# is translated. Running this script will output a list of translation keys that
# are remaining to be translated.
# The script only checks your custom translations. It does not check the Rails
# translations too. If you want to do that just remove the I18n.load_path = ...
# The script expects:
# 1. to be placed in a subdirectory of script
# 2. the primary language is :en
# 3. translation files are in files are in config/locales/ and subdirectories
require File.dirname(__FILE__) + '/../../config/environment'
# Return a new hash with all the keys converted to . format
def dotize(hash, result = {}, parents = "")
hash.each do |key, value|
if value.kind_of? Hash
dotize(value, result, "#{parents}.#{key}")
elsif !value.blank?
result["#{parents}.#{key}"] = value
end
end
result
end
# Load only our custom locale files
I18n.load_path = Dir[File.join(RAILS_ROOT, 'config', 'locales', '**', '*.{rb,yml}')]
locales = I18n.available_locales - [:en]
translations = I18n.backend.send(:translations)
english_dotized = dotize(translations[:en])
locales.each do |locale|
locale_dotized = dotize(translations[locale])
puts "Keys in English not in #{locale}"
puts (english_dotized.keys - locale_dotized.keys).sort.collect {|k| "#{k}: \"#{english_dotized[k]}\""}
puts
puts "Keys in #{locale} not in English"
puts (locale_dotized.keys - english_dotized.keys).sort.collect {|k| "#{k}: \"#{locale_dotized[k]}\""}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment