Last active
December 30, 2015 11:09
-
-
Save pinzolo/7820742 to your computer and use it in GitHub Desktop.
各辞書ファイルに未登録の可能性があるキーを列挙する
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
# coding: utf-8 | |
require "yaml" | |
def to_flat(key, value) | |
{}.tap do |dic| | |
if value.is_a?(Hash) | |
value.each do |k, v| | |
dic.merge!(to_flat("#{key}.#{k}", v)) | |
end | |
else | |
dic[key] = value | |
end | |
end | |
end | |
dir = ARGV.first || File.dirname(__FILE__) | |
yml_paths = Dir.glob(File.join(dir, "**", "*.yml")) | |
keys_per_locale = yml_paths.each_with_object({}) do |yml_path, tmp_data| | |
locale = File.basename(yml_path, ".*") | |
tmp_data[locale] ||= [] | |
yml = YAML.load_file(yml_path) | |
next unless yml[locale] | |
flat_dict = yml[locale].inject({}) do |map, (k, v)| | |
map.merge(to_flat(k, v)) | |
end | |
tmp_data[locale] += flat_dict.keys | |
end | |
all_keys = keys_per_locale.values.inject(:+).uniq | |
result = keys_per_locale.each_with_object({}) do |(k, v), tmp_result| | |
lost = all_keys - v | |
tmp_result[k] = lost unless lost.empty? | |
end | |
result.each do |locale, losts| | |
puts "#{locale} => {" | |
losts.each do |lost| | |
puts " #{lost}" | |
end | |
puts "}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment