class TranslationIO::Client::BaseOperation::SaveNewPoFilesStep

Public Class Methods

new(target_locales, locales_path, parsed_response) click to toggle source
# File lib/translation_io/client/base_operation/save_new_po_files_step.rb, line 5
def initialize(target_locales, locales_path, parsed_response)
  @target_locales  = target_locales
  @locales_path    = locales_path
  @parsed_response = parsed_response
end

Public Instance Methods

run() click to toggle source
# File lib/translation_io/client/base_operation/save_new_po_files_step.rb, line 11
def run
  TranslationIO.info "Saving new PO files."

  text_domain = TranslationIO.config.text_domain

  @target_locales.each do |target_locale|
    if @parsed_response.has_key?("po_data_#{target_locale}")
      po_path = File.join(@locales_path, Locale::Tag.parse(target_locale).to_s, "#{text_domain}.po")
      FileUtils.mkdir_p(File.dirname(po_path))
      TranslationIO.info po_path, 2, 2

      File.open(po_path, 'wb') do |file|
        file.write(@parsed_response["po_data_#{target_locale}"])
      end
    end
  end

  return self
end