Sha256: dcec44372a87eb01289df78e805d8879ffe3d51407f3ea85845f1af88684fce9

Contents?: true

Size: 1.11 KB

Versions: 7

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

7 entries across 7 versions & 1 rubygems

Version Path
faalis-2.0.4 lib/tasks/faalis_tasks.rake
faalis-2.0.3 lib/tasks/faalis_tasks.rake
faalis-2.0.1 lib/tasks/faalis_tasks.rake
faalis-2.0.0 lib/tasks/faalis_tasks.rake
faalis-2.0.0.rc6 lib/tasks/faalis_tasks.rake
faalis-2.0.0.rc5 lib/tasks/faalis_tasks.rake
faalis-2.0.0.rc4 lib/tasks/faalis_tasks.rake