Class: XliffTransWriter
- Inherits:
-
Object
- Object
- XliffTransWriter
- Defined in:
- lib/transync/xliff_trans/xliff_trans_writer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#file ⇒ Object
Returns the value of attribute file.
-
#language ⇒ Object
Returns the value of attribute language.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path, file, data) ⇒ XliffTransWriter
constructor
A new instance of XliffTransWriter.
- #save ⇒ Object
Constructor Details
#initialize(path, file, data) ⇒ XliffTransWriter
Returns a new instance of XliffTransWriter.
9 10 11 12 13 14 |
# File 'lib/transync/xliff_trans/xliff_trans_writer.rb', line 9 def initialize(path, file, data) @path = path @file = file @language = data[:language] @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/transync/xliff_trans/xliff_trans_writer.rb', line 4 def data @data end |
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/transync/xliff_trans/xliff_trans_writer.rb', line 4 def file @file end |
#language ⇒ Object
Returns the value of attribute language.
4 5 6 |
# File 'lib/transync/xliff_trans/xliff_trans_writer.rb', line 4 def language @language end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/transync/xliff_trans/xliff_trans_writer.rb', line 4 def path @path end |
Instance Method Details
#save ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/transync/xliff_trans/xliff_trans_writer.rb', line 16 def save translations = data[:translations] xml = Builder::XmlMarkup.new( :indent => 4 ) xml.instruct! :xml, :encoding => 'UTF-8' xml.xliff :version => '1.2', :xmlns => 'urn:oasis:names:tc:xliff:document:1.2' do |xliff| xliff.file :'source-language' => language, :datatype => 'plaintext', :original => 'file.ext' do |file| file.body do |body| translations.each do |trans| body.tag! 'trans-unit', :id => trans[:key] do |trans_unit| trans_unit.source trans[:key] trans_unit.target trans[:value] end end end end end File.open(file_path, 'w') { |file| file.write(xml.target!) } end |