Class: Translatomatic::Translator::MyMemory
- Defined in:
- lib/translatomatic/translator/my_memory.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MyMemory
constructor
Create a new MyMemory translator instance.
-
#upload(tmx) ⇒ Object
Upload a set of translations to MyMemory.
Methods inherited from Base
Methods included from Util
Constructor Details
#initialize(options = {}) ⇒ MyMemory
Create a new MyMemory translator instance
14 15 16 17 18 19 20 21 |
# File 'lib/translatomatic/translator/my_memory.rb', line 14 def initialize( = {}) super() @key = [:mymemory_api_key] || ENV["MYMEMORY_API_KEY"] @email = [:mymemory_email] || ENV["MYMEMORY_EMAIL"] @query_options = {} @query_options.merge!(de: @email) if @email @query_options.merge!(key: @key) if @key end |
Instance Method Details
#upload(tmx) ⇒ Object
Upload a set of translations to MyMemory
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/translatomatic/translator/my_memory.rb', line 30 def upload(tmx) request = Translatomatic::HTTPRequest.new(UPLOAD_URL) request.start do |http| body = [ request.file(key: :tmx, filename: "import.tmx", content: tmx.to_xml, mime_type: "application/xml" ), request.param(key: :private, value: 0) ] response = request.post(body, multipart: true) log.debug("share response: #{response.body}") end end |