Sha256: 1e0cb3d1aa9e7d966c568282e10c411affdff94f0bfd15377e155d23fc870b6c

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

gettext_find_task = begin
                      Rake::Task['gettext:find']
                    rescue
                      nil
                    end

if gettext_find_task
  namespace :gettext do
    task :store_action_names => :environment do
      storage_file = "#{locale_path}/action_names.rb"
      method_names = [:plan, :run, :finalize]
      instances = Actions::EntryAction
                  .descendants
                  .uniq
                  .map(&:allocate)
                  .select do |action|
        method_names.any? do |method_name|
          if action.respond_to?(method_name)
            src, = action.method(method_name).source_location
            src.start_with? @engine.root.to_s
          end
        end
      end

      if instances.any?
        puts "writing action translations to: #{storage_file}"

        File.write storage_file,
                   "# Autogenerated!\n" +
                   instances
                   .map { |instance| %[_("#{instance.humanized_name}")] }
                   .sort
                   .join("\n") + "\n"
      elsif File.exist? storage_file
        puts "Removing empty action translations file: #{storage_file}"
        File.delete storage_file
      end
    end
  end

  gettext_find_task.enhance ['gettext:store_action_names']
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 lib/tasks/gettext.rake
foreman-tasks-10.0.1 lib/tasks/gettext.rake