Sha256: 90ebc5a5254e6982fe6eb18df564e6e1f528fdc1e511a157d7b4d91ba26b1987
Contents?: true
Size: 1.11 KB
Versions: 8
Compression:
Stored size: 1.11 KB
Contents
namespace :faalis do namespace :i18n do desc 'Add all the missing keys to the locale files' task :collect do def merge_recursively(a, b) #puts "Rec: ", a, b return b if a.is_a?(String) a.merge(b) {|key, a_item, b_item| merge_recursively(a_item, b_item) } end Dir["#{Rails.root}/tmp/i18n/*"].each do |locale_file| locale = locale_file.split('/')[-1] if File.exist? "#{Rails.root}/config/locales/#{locale}.yml" raw_data = File.read("#{Rails.root}/config/locales/#{locale}.yml") locale_data = YAML.load(raw_data) else locale_data = {} end Dir["#{Rails.root}/tmp/i18n/#{locale}/*"].each do |key_file| key = key_file.split('/')[-1] #puts "Key", key title = key.split('.')[-1].titleize array = ::I18n.normalize_keys(locale, key, nil) tmp = array.reverse.inject(title) do |a, n| { n.to_s => a } end locale_data = merge_recursively(locale_data, tmp) end puts YAML.dump(locale_data)[4..-1] end end end end
Version data entries
8 entries across 8 versions & 1 rubygems