Created
November 12, 2009 03:52
-
-
Save maxime/232580 to your computer and use it in GitHub Desktop.
short script that finds and reports missing translation keys
This file contains hidden or 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
require "yaml" | |
desc "Find missing translations" | |
task :find_missing_translations do | |
base_locale = 'en' | |
locale_to_translate_in = 'zh-CN' | |
english_texts = YAML::load(File.read(File.join(RAILS_ROOT, 'config', 'locales', base_locale+".yml"))) | |
translations = YAML::load(File.read(File.join(RAILS_ROOT, 'config', 'locales', locale_to_translate_in+".yml"))) | |
puts "The following translations for '#{locale_to_translate_in}' are missing:" | |
find_missing_keys(english_texts[base_locale], translations[locale_to_translate_in]) | |
end | |
def find_missing_keys(first_hash, second_hash, prefix="") | |
first_hash.keys.each do |key| | |
if (second_hash.keys.include?(key)) | |
# exists, go deeper if it's a hash | |
if ((first_hash[key].class == Hash) && (second_hash[key].class == Hash)) | |
find_missing_keys(first_hash[key], second_hash[key], prefix+"#{key}:") | |
end | |
else | |
# doesn't exist, report | |
puts " #{prefix}#{key}:" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment