Class: LocoStrings::AndroidFile
- Defined in:
- lib/loco_strings/parsers/android_file.rb
Overview
AndroidFile is a class for working with Android localization strings.
Instance Attribute Summary
Attributes inherited from LocoFile
Instance Method Summary collapse
Methods inherited from LocoFile
#clean, #delete, #initialize, #update, #update_file_path, #value
Constructor Details
This class inherits a constructor from LocoStrings::LocoFile
Instance Method Details
#read ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/loco_strings/parsers/android_file.rb', line 9 def read clean return @strings unless File.exist?(@file_path) comment = nil doc = Nokogiri::XML(File.open(@file_path)) doc.xpath("//resources").first.children.each do |child| comment = extract_comment(child) || comment value = extract_string(child, comment) comment = nil if value end @strings end |
#write ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/loco_strings/parsers/android_file.rb', line 23 def write builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.resources do @strings.each do |key, value| xml.comment value.comment if value.comment xml.string(value.value, name: key) end end end File.write(@file_path, builder.to_xml) end |