Class: RailsWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/localio/writers/rails_writer.rb

Class Method Summary collapse

Class Method Details

.write(languages, terms, path, formatter, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/localio/writers/rails_writer.rb', line 7

def self.write(languages, terms, path, formatter, options)
  puts 'Writing Rails YAML translations...'

  languages.keys.each do |lang|
    output_path = path

    # We have now to iterate all the terms for the current language, extract them, and store them into a new array

    segments = SegmentsListHolder.new lang
    terms.each do |term|
      key = Formatter.format(term.keyword, formatter, method(:rails_key_formatter))
      translation = term.values[lang]
      segment = Segment.new(key, translation, lang)
      segment.key = nil if term.is_comment?
      segments.segments << segment
    end

    TemplateHandler.process_template 'rails_localizable.erb', output_path, "#{lang}.yml", segments
    puts " > #{lang.yellow}"
  end
end