Class: Translatomatic::Translator::MyMemory
- Defined in:
- lib/translatomatic/translator/my_memory.rb
Overview
Interface to the MyMemory translation API
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MyMemory
constructor
Create a new MyMemory translator instance.
-
#upload(tmx) ⇒ void
Upload a set of translations to MyMemory.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ MyMemory
Create a new MyMemory translator instance
16 17 18 19 20 21 22 23 |
# File 'lib/translatomatic/translator/my_memory.rb', line 16 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) ⇒ void
This method returns an undefined value.
Upload a set of translations to MyMemory
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/translatomatic/translator/my_memory.rb', line 33 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(t("translator.share_response", response: response.body.inspect)) end end |