Method: Twine::Formatters::Android#read

Defined in:
lib/twine/formatters/android.rb

#read(io, lang) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/twine/formatters/android.rb', line 61

def read(io, lang)
  document = REXML::Document.new io, :compress_whitespace => %w{ string }
  document.context[:attribute_quote] = :quote
  comment = nil
  document.root.children.each do |child|
    if child.is_a? REXML::Comment
      content = child.string.strip
      content.gsub!(/[\s]+/, ' ')
      comment = content if content.length > 0 and not content.start_with?("SECTION:")
    elsif child.is_a? REXML::Element
      next unless child.name == 'string'

      key = child.attributes['name']

      content = child.children.map(&:to_s).join
      set_translation_for_key(key, lang, content)
      set_comment_for_key(key, comment) if comment

      comment = nil
    end 
  end
end