class LokaliseRails::TaskDefinition::Exporter

Public Class Methods

do_upload(f_path, r_path) click to toggle source

Performs the actual file uploading to Lokalise. If the API rate limit is exceeed, applies exponential backoff

# File lib/lokalise_rails/task_definition/exporter.rb, line 29
def do_upload(f_path, r_path)
  with_exp_backoff(LokaliseRails.max_retries_export) do
    api_client.upload_file project_id_with_branch, opts(f_path, r_path)
  end
end
each_file() { |full_path, relative_path| ... } click to toggle source

Processes each translation file in the specified directory

# File lib/lokalise_rails/task_definition/exporter.rb, line 36
def each_file
  return unless block_given?

  loc_path = LokaliseRails.locales_path
  Dir["#{loc_path}/**/*"].sort.each do |f|
    full_path = Pathname.new f

    next unless file_matches_criteria? full_path

    relative_path = full_path.relative_path_from Pathname.new(loc_path)

    yield full_path, relative_path
  end
end
export!() click to toggle source

Performs translation file export from Rails to Lokalise and returns an array of queued processes

@return [Array]

# File lib/lokalise_rails/task_definition/exporter.rb, line 12
def export!
  check_options_errors!

  queued_processes = []
  each_file do |full_path, relative_path|
    queued_processes << do_upload(full_path, relative_path)
  rescue StandardError => e
    raise e.class, "Error while trying to upload #{full_path}: #{e.message}"
  end

  $stdout.print 'Task complete!'

  queued_processes
end
file_matches_criteria?(full_path) click to toggle source

Checks whether the specified file has to be processed or not

@return [Boolean] @param full_path [Pathname]

# File lib/lokalise_rails/task_definition/exporter.rb, line 72
def file_matches_criteria?(full_path)
  full_path.file? && proper_ext?(full_path) &&
    !LokaliseRails.skip_file_export.call(full_path)
end
opts(full_p, relative_p) click to toggle source

Generates export options

@return [Hash] @param full_p [Pathname] @param relative_p [Pathname]

# File lib/lokalise_rails/task_definition/exporter.rb, line 56
def opts(full_p, relative_p)
  content = File.read full_p

  initial_opts = {
    data: Base64.strict_encode64(content.strip),
    filename: relative_p,
    lang_iso: LokaliseRails.lang_iso_inferer.call(content)
  }

  initial_opts.merge LokaliseRails.export_opts
end