Sha256: 1a8d8a543e91c01be9963e021d128f712fb4a10d3ee4306fd390fb2e0a4642db

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

require_relative './phrase_app_client'
require 'tempfile'

class PhraseApp::Android::Upload < PhraseApp::Android::PhraseAppClient

  def perform(locale = 'en')
    file = build_upload_file

    params = PhraseApp::RequestParams::UploadParams.new file: file.path, file_format: 'xml', locale_id: locale
    upload = client.upload_create project_id, params

    puts 'Successfully uploaded.'.green
    file.unlink

    upload
  end

  def build_upload_file
    tmp = Tempfile.new %w(translations .xml)

    doc = Nokogiri::XML::Document.new
    doc.encoding = 'utf-8'
    res = doc.create_element 'resources', 'xmlns:tools' => 'http://schemas.android.com/tools'
    doc.add_child res

    %w(strings arrays).each do |file|
      read_locale_file(file, nil).at('//resources').element_children.each do |el|
        res.add_child(el) if el.attr('tools:ignore').nil?
      end
    end

    tmp.write doc.to_xml(indent: 4)
    tmp.close
    tmp
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phraseapp_android-0.4.0 lib/phraseapp_android/upload.rb