require 'yaml' module MissingTranslation class YamlProcessor def self.denormalize_translations_hash(translations, parent_key='') ans = {} translations.each do |key, val| if val.is_a? Hash aux = denormalize_translations_hash(val, "#{parent_key}#{key}.") aux.each do |k, v| ans[k] = v end else ans["#{parent_key}#{key}"] = val end end ans end def self.dig_set(obj, keys, value) key = keys.first if keys.length == 1 obj[key] = value else obj[key] = {} unless obj[key] dig_set(obj[key], keys.slice(1..-1), value) end end def self.normalize_translations_hash(hash) result = {} hash.keys.sort.each do |key| dig_set(result, key.split("."), hash[key]) end result end end end