class XliffTransWriter
Public Class Methods
new(path, file)
click to toggle source
# File lib/transync/xliff_trans/xliff_trans_writer.rb, line 5 def initialize(path, file) @path = path @file = file end
Public Instance Methods
write(trans_hash)
click to toggle source
# File lib/transync/xliff_trans/xliff_trans_writer.rb, line 10 def write(trans_hash) language = trans_hash[:language] translations = trans_hash[: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.keys.each do |trans_key| body.tag! 'trans-unit', :id => trans_key do |trans_unit| trans_unit.source trans_key trans_unit.target translations[trans_key] end end end end end File.open(file_path(language), 'w') { |file| file.write(xml.target!) } end
Private Instance Methods
file_path(language)
click to toggle source
# File lib/transync/xliff_trans/xliff_trans_writer.rb, line 36 def file_path(language) "#{@path}/#{@file}.#{language}.xliff" end