Class: C11n::Exporter::Android

Inherits:
Object
  • Object
show all
Defined in:
lib/c11n/exporter/android.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Android

Returns a new instance of Android.



7
8
9
# File 'lib/c11n/exporter/android.rb', line 7

def initialize(options = {})
  @path = options[:path]
end

Instance Method Details

#export(translations, locale) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/c11n/exporter/android.rb', line 15

def export(translations, locale)
  builder = Nokogiri::XML::Builder.new(encoding: 'utf-8')
  types = translations.types

  root_node = builder.resources do |xml|
    translations.translations_for(locale).each do |key, translation|
      case types[key]
      when C11n::Types::ARRAY
        xml.send(:'string-array') do
          translation.each do |item|
            xml.item item
          end
        end
      when C11n::Types::CDATA
        xml.string { xml.cdata translation }
      else
        xml.string translation
      end['name'] = key
    end
  end

  file.print builder.to_xml
  file.close
end

#fileObject



11
12
13
# File 'lib/c11n/exporter/android.rb', line 11

def file
  @file ||= File.new(@path, 'w')
end