Class: Lokale::Importer::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/lokale/agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#langObject

Returns the value of attribute lang.



247
248
249
# File 'lib/lokale/agent.rb', line 247

def lang
  @lang
end

#lstringsObject

Returns the value of attribute lstrings.



247
248
249
# File 'lib/lokale/agent.rb', line 247

def lstrings
  @lstrings
end

#nameObject

Returns the value of attribute name.



247
248
249
# File 'lib/lokale/agent.rb', line 247

def name
  @name
end

Class Method Details

.from_file(xliff_path) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/lokale/agent.rb', line 249

def self.from_file(xliff_path)
  begin
    xliff = XLIFFer::XLIFF.new(File.open(xliff_path))  
  rescue Exception => e
    puts "Failed to parse `#{xliff_path}` file."
  end

  diffs = []

  xliff.files.each do |f|
    next if f.target_language == Config.get.main_lang
    next if f.source_language != Config.get.main_lang 

    diff = Diff.new
    diff.name = f.original
    diff.lang = f.target_language
    diff.lstrings = f.strings
      .map { |s| LString.from_xliff_string(s, f.target_language) }
      .delete_if { |ls| ls.target.nil? }
    next if diff.lstrings.empty?

    diffs << diff
  end
  diffs
end